自己做了一个下拉列表,能够动态从数据库获取数据,但无法排除下拉列表里重复的数据,求解决方法页面代码如下
<td>作者:</td>
<td align="left">
<select name="author" id="author">
<option value="">全部</option>
<%
List <BooksInformation> allAuthor = service.getAllAuthor();
for(BooksInformation Author : allAuthor){
%>
<option  value=<%=Author.getAuthor() %> <%=Author.equals(Author.getAuthor())?"selected":"" %>><%=Author.getAuthor()%></option>
<%} %>
</select>
</td>后台
public List<BooksInformation> getAllAuthor() throws DqMisException {
// TODO Auto-generated method stub
String hql="form "+BooksInformation.class.getName()+"as c where 1=1";
return HibernateServiceUtil.query(hql);
}

解决方案 »

  1.   

    补充一下,要用hql实现,貌似要用distinct,但我不会用,还望有人教一下!
      

  2.   

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"));
    projectionList.add(Projections.property("name"));
    c.setProjection(Projections.distinct(projectionList));
    List result = c.list();
      

  3.   

    String hql="select distinct(c) form "+BooksInformation.class.getName()+"as c where 1=1";
    试试。。看可以不。。
      

  4.   


     你不要拿个重复 在那个 字段前面加上distinct
      

  5.   


    //你直接这样写就行
    tring hql="select distinct 不允许重复的字段 form "+BooksInformation.class.getName()+"as c where 1=1";
      

  6.   

    //你直接这样写就行
    tring hql="select distinct 不允许重复的字段 form "+BooksInformation.class.getName()+"as c where 1=1";
      

  7.   

    兄弟,照你这么弄出现这个问题org.hibernate.QueryException: query must begin with SELECT or FROM: selcet [selcet distinct author from cn.ypeg.dqmis.portlet.books.model.BooksInformation as c where 1=1 ]
    难道说是对大小写敏感?
      

  8.   

    你在查询的时候就把重复的数据去掉!再在页面做显示!distinct 
      

  9.   

    能否告诉我怎样改查询,我用distinct试过好多次都没成功,最好根据我的代码把你改的附上,谢谢!
      

  10.   

    form ???用这个关键字能查出结果来?咱还是先确认下这个东西吧