打开编辑页面
dept-list.jsp
<button type="button" class="btn bg-olive btn-xs" onclick='location.href="${path}/system/dept/toUpdate.do?deptId=${dept.deptId}"'>编辑</button>
DeptController
// ${path}/system/dept/toUpdate.do?deptId=${dept.deptId}
@RequestMapping(path = "/toUpdate",method =RequestMethod.GET)
public String toUpdate(Model model, String deptId){
l.info("toUpdate deptId="+deptId);
return "system/dept/dept-update";
}
编辑页面的数据回显
先查找
TestDeptService
@Test
public void test04(){
String deptId="f2b9573f-c774-4464-8305-a8b2b1241765";
Dept dept=service.findById(deptId);
l.info("test04 dept="+dept);
}
IDeptService
//查找指定id的部门
Dept findById(String deptId);
DeptServiceImpl
@Override
public Dept findById(String deptId) {
return dao.findById(deptId);
}
IDeptDao
Dept findById(String deptId);
IDeptDao.xml
<select id="findById" parameterType="string" resultMap="findOneMap">
select * from pe_dept where dept_id=#{deptId}
</select>
再赋值
DeptController
@RequestMapping(path = "/toUpdate",method =RequestMethod.GET)
public String toUpdate(Model model,String deptId){
String companyId = "1";
l.info("toUpdate deptId="+deptId);
Dept dept = service.findById(deptId);
l.info("toUpdate dept="+dept);
List<Dept> list = service.findAll(companyId);
l.info("toUpdate list="+list);
model.addAttribute("dept",dept);
model.addAttribute("list",list);
return "/system/dept/dept-update";
}
编辑哪个部门的数据,就查该部门的数据就可以了,为什么还要查所有的部门?
因为页面有一个下拉菜单
dept-update.jsp
下拉菜单的回显
<div class="col-md-2 title">上级部门</div>
<div class="col-md-10 data line-height36">
<select class="form-control" name="parent.deptId">
<option value="" disabled="disabled">请选择</option>
<option value="">成为顶级部门</option>
<c:forEach items="${list}" var="item">
<option ${dept.parent.deptId == item.deptId ?'selected':''} value="${item.deptId}">${item.deptName}</option>
</c:forEach>
</select>
</div>
单选按钮的回显
<div class="col-md-2 title">状态</div>
<div class="col-md-10 data">
<div class="form-group form-inline">
<div class="radio"><label><input type="radio" ${dept.state==0?'checked':''} name="state" value="0">停用</label></div>
<div class="radio"><label><input type="radio" ${dept.state==1?'checked':''} name="state" value="1">启用</label></div>
</div>
</div>