数据库动态选择select下拉框
基于JFinal,jstl,Html
页面
<select name="uqid">
<option value="" selected="selected">选择区域</option>
<c:forEach items="${pageUtil.list}" var="lli">
<option value="${lli.qid}">${lli.qname}</option>
</c:forEach>
</select>
Controller
/**
* 跳转添加页
*/
public void userAddPage(){
PageUtil pageUtil = nsUserService.userGetQy();
setAttr("pageUtil",pageUtil);
renderJsp("/nsuser/nsUserEditAdd.jsp");
}
Service
/**
* 区域列表
*/
public PageUtil userGetQy(){
String sql="SELECT * FROM ns_qy where 1 = 1";
PageUtil pageUtil=new PageUtil(sql);
return pageUtil;
}
工具类PageUtil,分页工具类 改动 留下传List数据
package com.util;
import com.jfinal.plugin.activerecord.Db;
import java.util.List;
/**
*
* @param <T>
*/
public class PageUtil<T> {
private List<T> list;//分页中泛型类
private String sql;//sql语句
}
//PageUtil工具返回List
public PageUtil(String sql){
this.list= (List<T>) Db.find(sql);
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
}