MYSQL查询用户下多个角色信息

Posted it-way

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL查询用户下多个角色信息相关的知识,希望对你有一定的参考价值。

    <resultMap id="baseBeanUser" type="com.aisino.guard.vo.system.TUserVoOut">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="actualName" property="actualName"/>
        <result column="ipNum" property="ipNum"/>
        <result column="intime" property="intime"/>
        <result column="departmentName" property="departmentName"/>
        <result column="departmentId" property="departmentId"/>
        <collection
                property="roleNameLst"
                columnPrefix="r_"
                ofType="com.aisino.guard.entity.system.TRole"
        >
            <id column="id" property="id"/>
            <result column="name" property="name"/>
            <result column="deleted" property="deleted"/>
        </collection>
    </resultMap>

    <select id="queryUserPageLst" resultMap="baseBeanUser">
        select
            u.id as id,
            u.name as name,
            u.actual_name as actualName,
            u.ip_num as ipNum,
            u.intime as intime,
            u.department_id as departmentId,
            d.name as departmentName,
            r.id r_id,
            r.name r_name
        from
            t_user as u
        left join t_department as d
        on u.department_id = d.id
        left join t_user_role_rel as usrel
        on  u.id = usrel.ref_user_id
        left join t_role as r
        on r.id = usrel.ref_role_id
        <where>
            u.deleted = $@[email protected]_FLAG_N
            <if test="param.name != null">
                AND p.name = #param.name
            </if>
            <if test="param.actualName != null">
                AND u.actual_name = #param.actualName
            </if>
            <if test="param.departmentId != null">
                AND u.department_id = #param.departmentId
            </if>
        </where>
    </select>

 

以上是关于MYSQL查询用户下多个角色信息的主要内容,如果未能解决你的问题,请参考以下文章

Java mysql 多表联查 与循环查询组装数据

MySQL 数据库,如何分角色权限建表?

MySQL 权限管理表设计

MySQL 权限管理表设计

PHP:如果用户未按下提交按钮,Mysql 回滚多个查询(通过 ajax 完成)

阶段3 1.Mybatis_09.Mybatis的多表操作_8 mybatis多对多操作-查询角色获取角色下所属用户信息