pagehelper分页结果出错

pagehelper分页结果出错

在使用pagehelper分页时

 PageHelper.startPage(1,10).doSelectPageInfo(()->{
 sellerDao.selectList(Wrappers.<Seller>query(condition));
 });

查出的list比10条要少

原因:多表连接查询:一对多查询

<sql id="selectSql">
        select*from route as r
        left join category as c on r.cid=c.cid
        left join seller as s on s.sid=r.sid
        left join route_img as ri on r.rid=ri.rid
</sql>
<resultMap id="routeMap" type="route">
        <id column="rid" property="rid"></id>
        <result property="rname" column="rname"/>
        <result property="price" column="price"/>
        <result property="routeIntroduce" column="route_introduce"/>
        <result property="rdate" column="rdate"/>
        <result property="isThemeTour" column="is_theme_tour"/>
        <result property="count" column="count"/>
        <result property="cid" column="cid"/>
        <result property="rimage" column="rimage"/>
        <result property="sid" column="sid"/>
        <result property="sourceId" column="sourceId"/>
        <collection property="routeImgList" ofType="routeImg">
            <id column="rgid" property="rgid"></id>
            <result property="rid" column="rid"/>
            <result property="bigpic" column="bigpic"/>
            <result property="smallpic" column="smallpic"/>
        </collection>
</resultMap>
<select id="findById" resultMap="routeMap">
        <include refid="selectSql"></include>
</select>
pagehelper根据“多“(即conllection)的数量来查询了
解决方案:将原本1条sql的嵌套结果集查询,改为collection的select子查询来实现
<sql id="selectSql">
       SELECT *  FROM route
</sql>
<resultMap id="routeMap" type="route">
        <id column="rid" property="rid"></id>
        <association property="category" javaType="category" select="com.wzy.dao.CategoryDao.findById" column="cid">
            <id column="cid" property="cid"></id>
        </association>
        <association property="seller" javaType="seller" select="com.wzy.dao.SellerDao.findById" column="sid">
            <id column="sid" property="sid"></id>
        </association>
        <collection property="routeImgList" javaType="java.util.List" ofType="RouteImg" select="com.wzy.dao.RouteImgDao.findByRid" column="rid">
            <id column="rgid" property="rgid"></id>
        </collection>
</resultMap>
<select id="findById" resultMap="routeMap">
        <include refid="selectSql"></include>
</select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值