postman接口測(cè)試
你見過一個(gè)類中注入很多的bean嗎捻撑?比如說像這樣
image
這個(gè)是接著上次的文章斥赋,雖然也是用程序?qū)嵙?xí)關(guān)聯(lián)的一種解決方案
再來看看Controller中的方法 (service中的方法就是上次文章中的方法體中的方法)
/**
* 查詢?cè)撚脩粝滤械臋?quán)限
*/
@RequestMapping("/queryauth")
public List<String> queryUserAuthorities(User user){
UserVo userVo = userService.queryAuth(user);
List<String> authorityList = new ArrayList<>();
HashSet<RoleVo> roleVos = userVo.getRoleVos();
Iterator<RoleVo> iterator = roleVos.iterator();
while (iterator.hasNext()){
RoleVo next = iterator.next();
HashSet<AuthorityVo> authorityVos = next.getAuthorityVos();
Iterator<AuthorityVo> it = authorityVos.iterator();
while (it.hasNext()){
AuthorityVo authorityVo = it.next();
authorityList.add(authorityVo.getAname());
}
}
return authorityList;
}
看起來是不是有點(diǎn)南轅北轍的感覺了颁褂,所以上次預(yù)留的連接查詢的接口就有用了(這里有個(gè)細(xì)節(jié)就是在創(chuàng)建意義上的中間表的時(shí)候,具體請(qǐng)去查看上一篇文章)
測(cè)試結(jié)果:
postman
Controller
@RequestMapping("/selectauth")
public List<Authority> selectUserAuthorities(User user){
List<Authority> authorityList = userService.selectUserAuth(user);
return authorityList;
}
Service
@Override
public List<Authority> selectUserAuth(User user) {
Integer uid = user.getUid();
List<Authority> authorityList = new ArrayList<>();
List<Integer> aids = userRoleMapper.selectUserAuth(uid);
for (Integer id:aids
) {
Authority authority = authorityMapper.getAuthorityById(id);
authorityList.add(authority);
}
return authorityList;
}
Mapper:
<select id="selectUserAuth" parameterType="INTEGER" resultType="integer">
select t_role_authority.aid from t_user_role inner JOIN
t_role_authority on t_user_role.rid = t_role_authority.rid where uid=#{uid};
</select>
一樣的實(shí)現(xiàn)了 查詢?cè)撚脩粝聯(lián)碛械乃袡?quán)限