mybatis查询结果一对多

<!--用户信息结果集-->
    <resultMap id="userResultMap" type="cn.com.xytkj.goods.entity.user.User">
        <id column="uid" property="id"/>
        <result column="user_name" property="userName"/>
        <result column="account" property="account"/>
        <result column="pwd" property="pwd"/>
        <result column="mail" property="mail"/>
        <result column="telephone" property="telephone"/>
        <result column="create_time" property="createTime"/>
        <result column="last_login_time" property="lastLoginTime"/>
        <result column="login_ip" property="loginIp"/>
        <result column="login_area" property="loginArea"/>
        <result column="salt" property="salt"/>
        <result column="user_status" property="userStatus"/>
        <collection property="roles" javaType="List" ofType="cn.com.xytkj.goods.entity.user.Role">
            <result column="rid" property="id"/>
            <result column="role_name" property="roleName"/>
            <result column="role_desc" property="roleDesc"/>
            <collection property="permissions" javaType="List" ofType="cn.com.xytkj.goods.entity.user.Permission">
                <result column="permission_name" property="permissionName"/>
                <result column="permission_desc" property="permissionDesc"/>
            </collection>
        </collection>
    </resultMap>
<!--查询用户-->
    <select id="findUser" resultMap="userResultMap">
        SELECT
	        u.id uid,
	        u.user_name,
	        u.account,
	        u.pwd,
	        u.mail,
	        u.telephone,
	        u.create_time,
	        u.last_login_time,
	        u.login_ip,
	        u.login_area,
	        u.user_status,
	        r.id rid,
	        r.role_name,
	        r.role_desc,
	        p.permission_name,
	        p.permission_desc
        FROM
	        t_user u
        LEFT JOIN
            t_user_role ur ON u.id = ur.user_id
        LEFT JOIN
            t_role r ON ur.role_id = r.id
        LEFT JOIN
            t_role_permission rp ON rp.role_id = r.id
        LEFT JOIN
            t_permission p ON p.id = rp.permission_id
        
    </select>

  查询结果有多个的时候可以用collection标签接收集合

上一篇:微服务统一管理swagger及简单接口测试功能


下一篇:面试官:MySQL如何实现查询数据并根据条件更新到另一张表?