一、需求描述
sys_column_role的id跟sys_column_role_permission的column_role_id关联
需要查询结果集1的所有数据,并且也要关联出结果集2的item_text数据
结果集1
SELECT [id]
,[role_name]
,[role_code]
,[description] from dbo.sys_column_role

结果集2
SELECT t1.[id]
,[column_role_id]
,[column_id]
,t2.[item_text]
,t2.[item_value]
FROM [dbo].[sys_column_role_permission] t1
left join sys_dict_item t2 on t1.[column_id]=t2.id collate database_default

二、项目代码
SysUserPrivilegesController
@RestController
@RequestMapping("/sys/privileges")
@Slf4j
@Api(value = "用户权限分配", tags = {
"用户权限分配"})
public class SysUserPrivilegesController {
@Autowired
ISysUserPrivilegesService sysUserPrivilegesService;
//查询所有
@RequestMapping(value = "/selectAll", method = RequestMethod.POST)
@ApiOperation("查询所有字段角色表")
@AutoLog(value = "查询所有字段角色表")
public Result selectAll() {
return sysUserPrivilegesService.selectAll();
}
}
ISysUserPrivilegesService
public interface ISysUserPrivilegesService {
//查询所有字段角色表
List selectAllColumnRole();
/*重构Controller方法如下*/
Result selectAll();
}
SysUserPrivilegesServiceImpl
@Service
public class SysUserPrivilegesServiceImpl implements ISysUserPrivilegesService {
@Resource
private SysUserPrivilegesMapper sysUserPrivilegesMapper;
@Autowired
ISysUserPrivilegesService sysUserPrivilegesService;
//查询所有字段角色表
@Override
public List selectAllColumnRole() {
List

本文介绍了如何在SpringBoot项目中使用Mybatis进行多表关联查询,将查询结果集整合到一起。具体涉及sys_column_role和sys_column_role_permission两个表的关联,以及查询结果的字段拼接。在 SysUserPrivilegesServiceImpl 中实现了查询逻辑,通过Mapper接口完成SQL的执行,并在Controller中提供接口对外服务。
最低0.47元/天 解锁文章
3469

被折叠的 条评论
为什么被折叠?



