mybatis查询结果一对多
Posted 执笔coding
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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标签接收集合
以上是关于mybatis查询结果一对多的主要内容,如果未能解决你的问题,请参考以下文章