博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
不设外键:来看看上次预留的连接查询接口
阅读量:7080 次
发布时间:2019-06-28

本文共 1808 字,大约阅读时间需要 6 分钟。

img_9a887152c99b805607e787f205494995.png
postman接口测试

你见过一个类中注入很多的bean吗?比如说像这样

img_01861ce0a75047403e10420dd3e0d615.png
image

这个是接着上次的文章,虽然也是用程序实习关联的一种解决方案

再来看看Controller中的方法 (service中的方法就是上次文章中的方法体中的方法)

/**     * 查询该用户下所有的权限     */    @RequestMapping("/queryauth")    public List
queryUserAuthorities(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; }

看起来是不是有点南辕北辙的感觉了,所以上次预留的连接查询的接口就有用了(这里有个细节就是在创建意义上的中间表的时候,具体请去查看上一篇文章)

测试结果:

img_ef32a8e4b2c1cf7752da8016542818b2.png
postman

Controller

@RequestMapping("/selectauth")    public List
selectUserAuthorities(User user){ List
authorityList = userService.selectUserAuth(user); return authorityList; }

Service

@Override    public List
selectUserAuth(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/

你可能感兴趣的文章
如何启用Open vSwitch的日志功能以便调试和排障
查看>>
我的友情链接
查看>>
教你使用dsadd命令一键批量创建OU和用户(包含基础属性信息)
查看>>
中国vs日本之 nginx 爬虫配置
查看>>
ansible使用过程中遇到的问题
查看>>
平安云桌面常见问题
查看>>
linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结
查看>>
安装Redis
查看>>
Zend不支持php5.3、不支持Windows下非线程安全PHPFastCGI
查看>>
python查找并批量替换配置文件内容
查看>>
把1到100的数字拆分成字典中的两个键值对 python
查看>>
秒开缓存盒子
查看>>
晒奖品--参加《寻找隐藏在F1背后的IT“引擎”》家园有奖活动获奖
查看>>
linux 运维中常用的shell命令
查看>>
镜像YUM安装仓库(转载唐老师的github)
查看>>
再谈CENTOS下通过YUM和RPM快速获取相关工具(命令)所在软件包并安装
查看>>
如何合并多个excel文件
查看>>
我的友情链接
查看>>
剪贴板(进程通信)
查看>>
ISA2006端口映射
查看>>