[代码解析004] MybatisPlus之QueryWrapper、LambdaQueryWrapper以及LambdaQueryChainWrapper用法
作者:互联网
1、代码片段
/**
* 获取角色已分配菜单列表
* @param xxxRoleId
* @return RoleMenuList
*/
@ApiOperation(value = "获取角色已分配菜单列表")
@GetMapping(value = "/getRoleMenuList/{aaaRoleId}")
public AjaxResult getRoleMenuList(@PathVariable("aaaRoleId") String aaaRoleId){
//根据角色id查询角色菜单关联表查出所有角色菜单关联列表
LambdaQueryWrapper<AaaRoleMenu> aaaMenuEntityWrapper = new LambdaQueryWrapper<>();
aaaMenuEntityWrapper.eq(AaaRoleMenu::getDelFlag,NumberUtil.ZERO_STR);
aaaMenuEntityWrapper.eq(AaaRoleMenu::getRoleId, aaaRoleId);
List<SaaaRoleMenu> aaaRoleMenuList = aaaRoleMenuService.list(aaaMenuEntityWrapper);
//根据角色菜单关联表中的菜单id查询出菜单列表
Set<String> menuIdList = new HashSet<>();
if (!CollectionUtils.isEmpty(aaaRoleMenuList)){
menuIdList = aaaRoleMenuList.stream().collect(Collectors.groupingBy(SaaaRoleMenu::getMenuId)).keySet();
}
List<SaaaMenu> aaaMenuList = Lists.newArrayList();
if (!CollectionUtils.isEmpty(menuIdList)){
LambdaQueryWrapper<SaaaMenu> aaaMenuWrapper= new LambdaQueryWrapper<>();
aaaMenuWrapper.eq(SaaaMenu::getDelFlag,NumberUtil.ZERO_STR);
aaaMenuList = aaaMenuService.listByIds(menuIdList); //批量查询
}
return AjaxResult.success(aaaMenuList);
}
2、涉及源码
4、涉及知识点
参考文章:http://t.zoukankan.com/donleo123-p-14109889.html
mybatis plus 条件构造器queryWrapper学习
标签:QueryWrapper,LambdaQueryWrapper,菜单,MybatisPlus,角色,aaaRoleId,menuIdList,aaaMenuEn 来源: https://www.cnblogs.com/Code-Rain/p/16442813.html