tk.mybatis中使用PageHelper分页,嵌套导致数据不对,实际记录数已嵌套的子记录为准
解决方法:在xml里面修改sql写法
<?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" >
<mapper namespace="com.imooc.mapper.OrderMapperCustom">
<resultMap id="myOrderVo" type="com.imooc.pojo.vo.MyOrdersVo">
<id column="orderId" property="orderId"/>
<result column="createdTime" property="createdTime"/>
<result column="payMethod" property="payMethod"/>
<result column="realPayAmount" property="realPayAmount"/>
<result column="postAmount" property="postAmount"/>
<result column="orderStatus" property="orderStatus"/>
<collection property="subOrderItemList"
select="getSubItems"
column="orderId"
ofType="com.imooc.pojo.vo.MySubOrderItemVO">
<result column="itemId" property="itemId"/>
<result column="itemName" property="itemName"/>
<result column="itemImg" property="itemImg"/>
<result column="itemSpecName" property="itemSpecName"/>
<result column="buyCounts" property="buyCounts"/>
<result column="price" property="price"/>
</collection>
</resultMap>
<!--<select id="queryMyOrders" parameterType="map" resultMap="myOrderVo">
select
od.id as orderId,
od.created_time as createdTime,
od.pay_method as payMethod,
od.real_pay_amount as realPayAmount,
od.post_amount as postAmount,
os.order_status as orderStatus,
oi.item_id as itemId,
oi.item_name as itemName,
oi.item_img as itemImg,
oi.item_spec_name as itemSpecName,
oi.buy_counts as buyCounts,
oi.price as price
from orders od
left join order_status os on od.id=os.order_id
left join order_items oi on od.id = oi.order_id
where od.user_id=#{paramsMap.userId}
<if test="paramsMap.orderStatus != null">
and os.order_status=#{paramsMap.orderStatus}
</if>
and od.is_delete = 0
order by od.updated_time asc
</select>-->
<select id="queryMyOrders" parameterType="map" resultMap="myOrderVo">
select
od.id as orderId,
od.created_time as createdTime,
od.pay_method as payMethod,
od.real_pay_amount as realPayAmount,
od.post_amount as postAmount,
os.order_status as orderStatus
from orders od
left join order_status os on od.id=os.order_id
where od.user_id=#{paramsMap.userId}
<if test="paramsMap.orderStatus != null">
and os.order_status=#{paramsMap.orderStatus}
</if>
and od.is_delete = 0
order by od.updated_time asc
</select>
<select id="getSubItems" parameterType="string" resultType="com.imooc.pojo.vo.MySubOrderItemVO">
select
oi.item_id as itemId,
oi.item_name as itemName,
oi.item_img as itemImg,
oi.item_spec_name as itemSpecName,
oi.buy_counts as buyCounts,
oi.price as price
from order_items oi
where oi.order_id=#{orderId}
</select>
</mapper>
整体思路:先查询订单数据,再根据订单id,查询每个订单的订单商品数据