mybatis多表查询xml的demo

<?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">
   <!-- &lt;!&ndash; 开启二级缓存 &ndash;&gt;
    <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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值