0
点赞
收藏
分享

微信扫一扫

Day33项目saas-export项目-部门管理-打开编辑页面回显


打开了编辑页面

Day33项目saas-export项目-部门管理-打开编辑页面回显_下拉菜单

dept-update.jsp

​${path}/system/dept/toUpdate.do?deptId=${dept.deptId}​

DeptController

// ${path}/system/dept/toUpdate.do?deptId=${dept.deptId}
@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";
}

编辑页面的数据回显

先查找

TestDeptService

@Test
public void test04(){
//deptId=100101
String deptId="100101";
Dept dept = iDeptService.findById(deptId);

l.info("test04 dept="+dept);
}

IDeptService

//查找指定id的部门
Dept findById(String deptId);

DeptServiceImpl

@Override
public Dept findById(String deptId) {
return iDeptDao.findById(deptId);
}

再赋值

编辑哪个部门数据,就查该部门数据就可以,为什么还要查所有部门,​​因为页面有一个下拉菜单​

DeptController

// ${path}/system/dept/toUpdate.do?deptId=${dept.deptId}
@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>
</select>

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>
</select>

单选的回显

<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>

单选框的回显

<input type="radio" name="sex" value="1" >
<input type="radio" name="sex" value="0" checked >


举报

相关推荐

0 条评论