标签:his list array prepare ems 方式 后台 role 信息
.在javaBean中首先实例化
private String bmmc ; //实例化部门名称
private String ygjs; //实例化员工角色
public String getBmmc() {
return bmmc;
}
public void setBmmc(String bmmc) {
this.bmmc = bmmc;
}
public String getYgjs() {
return ygjs;
}
public void setYgjs(String ygjs) {
this.ygjs = ygjs;
}
2.在Dao中写查询方法
//查询部门名称
public List<Select> selectBmmc() throws SQLException {
String sql = "select ID,BM_MC from task_dept";
conn = getConn();
stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery(sql);
List<Select> bmmclist= new ArrayList<Select>();
while(rs.next()) {
Select bmmc = new Select();
bmmc.setBmid(rs.getInt("ID"));
bmmc.setBmmc(rs.getString("BM_MC"));
bmmclist.add(bmmc);
}
return bmmclist;
}
//查询员工角色
public List<Select> selectygjs() throws SQLException {
String sql = "select JS_MC from task_role";
conn = getConn();
stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery(sql);
List<Select> ygjslist= new ArrayList<Select>();
while(rs.next()) {
Select ygjs = new Select();
ygjs.setYgjs(rs.getString(1));
ygjslist.add(ygjs);
}
return ygjslist;
}
3.在servlet中调用Dao中的方法
else if(action != null && action.equals("selOne")) {
int id=Integer.valueOf(request.getParameter("id")); //得到jsp传过来的ID值
EmployeeDao employeeDao = new EmployeeDao();
try {
List employeeOne = employeeDao.getOne(id); //调用的查询一条信息的方法
SelectOptionDao sDao = new SelectOptionDao();
List bmmclist = new ArrayList();
List ygjslist = new ArrayList();
bmmclist = sDao.selectBmmc(); //调用在Dao中写的方法,查询部门
ygjslist = sDao.selectygjs(); //调用查询员工角色的方法
for(int i = 0;i<bmmclist.size();i++) {
Select bmmc =(Select) bmmclist.get(i); //for循环主要用来在后台检测是否能得到信息
}
for(int i = 0;i<ygjslist.size();i++) {
Select ygjs =(Select) ygjslist.get(i);
}
request.setAttribute("ygjslist",ygjslist); //向前台传信息
request.setAttribute("bmmclist",bmmclist);
request.setAttribute("employeeOne",employeeOne);
request.getRequestDispatcher("/employee/edit.jsp").forward(request, response);
}
4.jsp在前台页面用下拉框的方式显示
<select name="bmmc" >
<c:forEach items="${bmmclist}" var="e">
<option value="${e.bmid}" <c:if test="${e.bmid==i.deptid}">selected</c:if>>${e.bmmc}</option>
</c:forEach>
</select>
标签:his list array prepare ems 方式 后台 role 信息
原文地址:https://www.cnblogs.com/cjw554551/p/14091759.html