本文共 1808 字,大约阅读时间需要 6 分钟。
你见过一个类中注入很多的bean吗?比如说像这样
这个是接着上次的文章,虽然也是用程序实习关联的一种解决方案
再来看看Controller中的方法 (service中的方法就是上次文章中的方法体中的方法)/** * 查询该用户下所有的权限 */ @RequestMapping("/queryauth") public ListqueryUserAuthorities(User user){ UserVo userVo = userService.queryAuth(user); List authorityList = new ArrayList<>(); HashSet roleVos = userVo.getRoleVos(); Iterator iterator = roleVos.iterator(); while (iterator.hasNext()){ RoleVo next = iterator.next(); HashSet authorityVos = next.getAuthorityVos(); Iterator it = authorityVos.iterator(); while (it.hasNext()){ AuthorityVo authorityVo = it.next(); authorityList.add(authorityVo.getAname()); } } return authorityList; }
看起来是不是有点南辕北辙的感觉了,所以上次预留的连接查询的接口就有用了(这里有个细节就是在创建意义上的中间表的时候,具体请去查看上一篇文章)
测试结果:
Controller
@RequestMapping("/selectauth") public ListselectUserAuthorities(User user){ List authorityList = userService.selectUserAuth(user); return authorityList; }
Service
@Override public ListselectUserAuth(User user) { Integer uid = user.getUid(); List authorityList = new ArrayList<>(); List aids = userRoleMapper.selectUserAuth(uid); for (Integer id:aids ) { Authority authority = authorityMapper.getAuthorityById(id); authorityList.add(authority); } return authorityList; }
Mapper:
一样的实现了 查询该用户下拥有的所有权限
转载地址:http://lxvml.baihongyu.com/