用HQL语句只查询部分字段,且排除重复项,在JSP中用下拉列表来显示
/************************************************/
action中 为 htlist=manager.hotelTypeList(hotelHid);
/************************************************/
service中为
/************************************************/
/**
*得到该酒店所有的房型
*
* @return
*/
@SuppressWarnings("unchecked")
public List hotelTypeList(String hotelHid) {
// String sql = " select distinct (ROOM_TYPE) FROM YC_HOTEL_ROOM_T hr ";
// sql += " WHERE hr.HID = '" + hotelHid + "'";
// sql += " ORDER BY hr.RID ASC";
String hql ="select distinct(t.roomType) from HotelRoom t where t.hotelInfo.hid='"+hotelHid+"'";
List list = null;
try{
// list = hotelRoomDAO.findBySql(sql, 0, 999);
list = hotelRoomDAO.findAllByHql(hql);
}catch (Exception e) {
e.printStackTrace();
}
return list;
}
/************************************************/
JSP中的代码为(显示上次搜索的内容):
<select name="room_Type" id="room_Type" >
<option vlaue=""></option>
<s:iterator value="htlist" id="bean">
<s:if test='#bean==room_Type'>
<option vlaue="${bean}" selected="selected" >${bean}</option>
</s:if>
<s:else>
<option vlaue="${bean}">${bean}</option>
</s:else>
</s:iterator>
</select>
/************************************************/