<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--UsersMapper映射到daoMapper接口处-->
<mapper namespace="com.wendao.auth.mapper.UsersMapper">
<!-- <!– 开启二级缓存 –>
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>-->
<resultMap id="usersAndRole" type="com.wendao.entity.auth.Users">
<id column="uid" property="id"></id>
<result column="email" property="email"/>
<result column="username" property="username"/>
<result column="pwd" property="pwd"/>
<result column="join_time" property="joinTime"/>
<result column="phonenum" property="phonenum"/>
<result column="stat" property="stat"/>
<collection property="roles" ofType="com.wendao.entity.auth.Role">
<id property="id" column="rid"></id>
<result property="roleName" column="roleName"></result>
<result property="roleDesc" column="roleDesc"></result>
</collection>
</resultMap>
<select id="selectUsersAndRole" resultMap="usersAndRole">
SELECT users.id as uid,users.email,users.pwd,users.join_time,users.username,users.phonenum,users.stat,users.join_time,role.id as rid,role.roleName,role.roleDesc FROM
users LEFT JOIN users_role
ON users.id=users_role.userId
LEFT JOIN role
ON role.id = users_role.roleId
</select>
<select id="findById" parameterType="java.lang.Integer" resultType="com.wendao.entity.auth.Users">
select *from users where id=#{id}
</select>
</mapper>
mybatis多表查询xml的demo
最新推荐文章于 2024-09-12 21:33:10 发布