基于权限管理时的用户角色权限处理。

实体类:

  1.User

  public class User{
private Integer uid;
private String username;
private String password;
private Set<Role> roles=new HashSet<>();
 2.Role
  public class Role {
private Integer rid;
private String rname;
private Set<Module> modules=new HashSet<>();
 3.Module
  

MYBATIS多层嵌套查询
    




MYBATIS多层嵌套查询

Mapper 文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<resultMap >
       <id property="uid" column="uid"/>
       <result property="username" column="username"/>
       <result property="password" column="password"/>
       <collection property="roles" ofType="roleMap" column="uid" select="findRole"></collection>
   </resultMap>
 
   <resultMap >
       <id property="rid" column="rid"/>
       <result property="rname" column="rname"/>
       <collection property="modules" ofType="com.example.mapper.entity.Module" column="rid" select="findModule">
       </collection>
   </resultMap>
 
     <select >
         SELECT  * from USER WHERE username=#{username}
     </select>
 
   <select >
       SELECT r.* from Role r LEFT  JOIN  user_role ur on ur.rid =r.rid where ur.uid=#{uid}
   </select>
 
   <select >
       SELECT m.* from module m LEFT  JOIN  module_role mr on mr.mid =m.mid where mr.rid=#{rid}
   </select>

  测试结果。

User{uid=1, username='hlhdidi', password='123', roles=[Role{rid=1, rname='admin',modules=[Module{mid=2, mname='delete'}, Module{mid=3, mname='query'}, Module{mid=4, mname='update'}, Module{mid=1, mname='add'}]}]}

  

基于权限管理时的用户角色权限处理。

实体类:

  1.User

  public class User{
private Integer uid;
private String username;
private String password;
private Set<Role> roles=new HashSet<>();
 2.Role
  public class Role {
private Integer rid;
private String rname;
private Set<Module> modules=new HashSet<>();
 3.Module
  

MYBATIS多层嵌套查询
    




MYBATIS多层嵌套查询

Mapper 文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<resultMap >
       <id property="uid" column="uid"/>
       <result property="username" column="username"/>
       <result property="password" column="password"/>
       <collection property="roles" ofType="roleMap" column="uid" select="findRole"></collection>
   </resultMap>
 
   <resultMap >
       <id property="rid" column="rid"/>
       <result property="rname" column="rname"/>
       <collection property="modules" ofType="com.example.mapper.entity.Module" column="rid" select="findModule">
       </collection>
   </resultMap>
 
     <select >
         SELECT  * from USER WHERE username=#{username}
     </select>
 
   <select >
       SELECT r.* from Role r LEFT  JOIN  user_role ur on ur.rid =r.rid where ur.uid=#{uid}
   </select>
 
   <select >
       SELECT m.* from module m LEFT  JOIN  module_role mr on mr.mid =m.mid where mr.rid=#{rid}
   </select>

  测试结果。

User{uid=1, username='hlhdidi', password='123', roles=[Role{rid=1, rname='admin',modules=[Module{mid=2, mname='delete'}, Module{mid=3, mname='query'}, Module{mid=4, mname='update'}, Module{mid=1, mname='add'}]}]}

  

相关文章:

  • 2021-11-22
  • 2021-10-01
  • 2021-11-14
  • 2021-06-15
  • 2021-12-22
  • 2021-04-08
  • 2022-12-23
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2021-12-19
  • 2022-01-21
  • 2022-12-23
相关资源
相似解决方案