功能需求
打开编辑页面,页面包含 下拉菜单与 单选框架将指定id的部门数据回显在编辑页面
查找所选id
测试代码TestDeptService
@Test
public void test04(){
//deptId=100101
String deptId="100101";
Dept dept = iDeptService.findById(deptId);
l.info("test04 dept="+dept);
}
IDeptService
Dept findById(String deptId);
DeptServiceImpl
@Override
public Dept findById(String deptId) {
return iDeptDao.findById(deptId);
}
DeptController
@RequestMapping(path="/toUpdate",method ={ RequestMethod.GET, RequestMethod.POST})
public String toUpdate(Model model, String deptId){
l.info("toUpdate deptId="+deptId);
return "system/dept/dept-update";
}
再赋值
因为页面有下拉菜单,所以还要检查所有部门
DeptController
@RequestMapping(path="/toUpdate",method ={ RequestMethod.GET, RequestMethod.POST})
public String toUpdate(Model model, String deptId){
String companyId = "1";
l.info("toUpdate deptId="+deptId);
//查询部门
Dept dept = iDeptService.findById(deptId);
l.info("toUpdate dept="+dept);
List<Dept> list = iDeptService.findAll(companyId);
model.addAttribute("dept",dept);
model.addAttribute("list",list);
return "system/dept/dept-update";
}
dept-update.jsp
下拉菜单回显
<select class="form-control" name="parent.deptId">
<option value="">成为顶级部门</option>
<c:forEach items="${list}" var="item">
<option ${dept.parent.deptId == item.deptId ?'selected':''} value="${item.deptId}">${item.deptName}</option>
</c:forEach>
<lect>
select标签的回显
<select name="parentId">
<option value="1">部门1</option>
<option value="2">部门2</option>
<option selected value="3">部门3</option>
<option value="4">部门4</option>
<lect>
单选的回显
<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>
单选框的回显
查询数据是0
<input type="radio" name="sex" value="1" >男
<input type="radio" name="sex" value="0" checked >女