我用的是 struts2+Hibernate+Spring  框架
我的后台代码
public List<Petinfo> findAll() {
String hql = "from Petinfo petinfo";
return (List<Petinfo>) this.getHibernateTemplate().find(hql);
}我的页面下拉框代码
<select name="pid">
<option>--请选择--</option>
<s:iterator value="#request.slist" id="petinfo">
<s:if test="#petinfo.getpetId==pid">
<option value="${petinfo.petId }" selected="selected">${petinfo.petOwnerName }</option>
</s:if>
<s:else>
<option value="${petinfo.petId }">${petinfo.petOwnerName }</option>
</s:else>
</s:iterator>
</select>请教大家 我判断的是在同一张表中,而且数据有重复的。 怎么让他下拉出来选择的数据没有重复的?

解决方案 »

  1.   

    重复的数据在sql里面distinct掉就行啦嘛,为什么要在页面上处理呢
      

  2.   

    distinct用过了报错。。node to traverse cannot be null!
      

  3.   

    你的hql语句怎么写的?
    hql支持distinct啊
      

  4.   

    List在页面展现之前处理一下就行了
      

  5.   

    把你的List换成Set。
    Petinfo重写equals和hsahcode方法。
    只要主键相等就返回true。
      

  6.   

    我不理解,既然是from table,怎么会出现重复数据呢?
    你又没选择字段,而是把所有的字段都检索出来。任意两条数据,至少会有主键不一样吧?
      

  7.   

    1 在struts2中进行判断2 为什么你的select 不用struts2的呢~ 你那样判断哪个项被选中多累啊
    <s:select name="pid" cssClass="select" id="reason"
    value="%{petinfo.petId }" list="#{'1','2','3','4'}" ></s:select>
    这样的话 如果petinfo.petId =2的话 2这一项会自动的被选中
      

  8.   

    上面的 找不到jsp代码标签 就只好用php标签了