1[代码解析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、涉及知识点