您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
15-Spring练习-用户添加操作-添加页面展示
发布时间:2025-01-08 22:51:38编辑:雪饮阅读()
-
在pages/user-list.jsp中找到新建的按钮,在修改器location.href的路径如:
<button type="button" class="btn btn-default" title="新建" onclick="location.href='${pageContext.request.contextPath}/user/saveUI'">
<i class="fa fa-file-o"></i> 新建
</button>
然后UserController控制器中对应完成该路径的方法
@Autowired
private RoleService roleService;
@RequestMapping("/saveUI")
public ModelAndView saveUI(){
ModelAndView modelAndView=new ModelAndView();
List<Role> roleList=roleService.list();
modelAndView.addObject("roleList",roleList);
modelAndView.setViewName("user-add");
return modelAndView;
}
然后在pages/user-add.jsp中将添加用的表单中用户角色下面将原本静态的用户角色列表遍历出来。
<div class="col-md-10 data">
<c:forEach items="${roleList}" var="role">
<input class="" type="checkbox" name="roleIds" value="${role.id}">${role.roleName}
</c:forEach>
</div>
关键字词:Spring,用户添加