后台代码:
model层
- public List getMaterielttypeList() throws Exception{
- List objList = new ArrayList();
- MaterieltypeHome mtype = this.getMaterielTypeHome();
- mtype.resetConditions();
- mtype.setOrderbyclause("order by typename");
- Collection mtypelist = mtype.findAll();
- Iterator it = mtypelist.iterator();
- while(it.hasNext()){
- Materieltype obj = (Materieltype) it.next();
- //固定写法,LabelValueBean()第一个参数为displayname,第二个参数为后台使用的值,一般为id。
- objList.add(new LabelValueBean(obj.getTypename(),String.valueOf(obj.getId())));
- }
- return objList;
- }
Action代码
- //实例化model
- LldServices services = new LldServices(conn);
- //取出list并设置到request属性中。
- request.setAttribute("mtypelist", services.getMaterielttypeList());
表现层:
- <html:select property="typeid">
- <!--mtypelist为request中设置的属性值 labelProperty="label" property="value"固定写法-->
- <html:options collection="mtypelist" labelProperty="label" property="value" />
- </html:select>