mybatis高级映射之一对多映射 一个用户拥有多个角色,每个角色拥有多个权限

一个用户拥有多个角色,每个角色拥有多个权限

一、先实现一个用户拥有多个角色

1. UserMapper.xml中:

 <resultMap id="userRoleListMap1" extends="userMap"
               type="com.example.simple.model.SysUser">
        <collection property="roleList" columnPrefix="role_"
                    resultMap="com.example.simple.mapper.RoleMapper.rolePrivilegeListMap"/>

    </resultMap>

 

<select id="selectAllUsersAndRoles1" resultMap="userRoleListMap1">
        select
            u.id,
            u.user_name,
            u.user_password,
            u.user_email ,
            u.user_info ,
            u.head_img,
            u.create_time ,
            r.id role_id,
            r.role_name  role_role_name,
            r.enabled role_enabled ,
            r.create_by role_create_by ,
            r.create_time role_create_time,
            p.id role_privilege_id ,
            p.privilege_name role_privilege_privilege_name ,
            p.privilege_url role_privilege_privilege_url
            from sys_user u
            inner join sys_user_role ur on u.id = ur.user_id
            inner join sys_role r on ur.role_id = r.id
            inner join sys_role_privilege rp on rp.role_id = r.id
            inner join sys_privilege p on p.id = rp.privilege_id
    </select>

 

2. 

上一篇:minetest no privilege


下一篇:CCF CSP 201612-3权限查询(c++100)