mybatis多表联查sql语句//⼀对⼀关联查询,以订单为中⼼关联⽤户 l
定义返回结果集 orders属性含有user对象
<resultMap id="order" type="pojo.Orders">
<id property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="number" column="number"/>
<result property="createtime" column="createtime"/>
<association property="user" javaType="pojo.User">
<result property="id" column="user_id"/>
<result property="username" column="username"/>
</association>
</resultMap>
<select id="selectOrders" resultMap="order">
select o.id,
o.user_id,
o.number,
u. username
from orders o
left join user u
on o.user_id = u.id
</select>
<resultMap id="user" type="pojo.User">
<id property="id" column="user_id"/>
<result property="username" column="username"/>
<collection property="ordersList" ofType="pojo.Orders">
<id property="id" column="id"/>
<result property="number" column="number"/>sql left join 多表连接
<result property="createtime" column="createtime"/>
</collection>
</resultMap>
<select id="selectUser" resultMap="user" >
select o.id,
o.user_id,
o.number,
u.username from user u left join orders o on u.id = o.user_id
</select>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论