81,092
社区成员
发帖
与我相关
我的任务
分享
<s:select list="pairsList" name="favorableBean.roomTypeId" listKey="key" listValue="value" value="favorableBean.roomTypeId"></s:select>
<s:property value="favorableBean.roomTypeId"/>
public class FavorableBean {
private int favorableId;
private Date inTime;
private Date outTime;
private String roomTypeId;
private int stayDay;
private String description;
//对应 get()/set() 方法
}
public class PairsBean {
private String key;
private String value;
//下面是对应的 get()/set() 方法
}
/*
* 得到房间类型的 键 - 值 对
*/
public List<PairsBean> getRoomType(){
List<PairsBean> pairsList = new ArrayList<PairsBean>();
PairsBean pairs = null;
try{
if( null == conn || conn.isClosed() ){
conn = this.dataSource.getConnection();
}
String strsql = "select id,roomType from SYS_RoomType"; //id在数据库中是 int 类型
pstmt = conn.prepareStatement(strsql);
rs = pstmt.executeQuery();
while(rs.next()){
pairs = new PairsBean();
pairs.setKey(String.valueOf(rs.getInt("id")));
pairs.setValue(rs.getString("roomType"));
pairsList.add(pairs);
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
this.closeAll(rs, pstmt, conn);
}
return pairsList;
}
private List<PairsBean> pairsList ;
pairsList = this.favorableService.getRoomType();
for( PairsBean bean : pairsList){
System.out.println(bean.getKey() + " " + bean.getValue());
//这里可以得到值 key --- value
}
<select name="favorableBean.roomTypeId" >
<%for(PairsBean bean : list){%>
<option value="<%=bean.getKey()%>"><%=bean.getValue()%></option>
<%} %>
String roomItem = (String)request.getAttribute("roomItem");
document.getElementById("favorableBean.roomTypeId").value=<%=roomItem%>;
<s:property id="room" value="favorableBean.roomTypeId"/>
<s:select list="pairsList" name="favorableBean.roomTypeId" listKey="key" listValue="value" value="%{#room}"></s:select>
String roomItem = (String)request.getAttribute("roomItem");