项目中使用PageHelper进行分页查询的时候,发现分页有问题:每页显示的数量与传入的limit的参数不一致。
    细细查看之后,发现是由于查询SQL是一对多查询,才会出现这样的问题。在网上查找了一些解决方案后,最终解决了,下面是整个查找问题、解决问题的记录。

    1. <resultMap id="GoodsList" type="com.cc.shoppingmall.pojo.vo.goods.GoodsDetailWx">
    2. <id column="id" property="id"/>
    3. <result column="goods_image" property="goodsImage"/>
    4. <result column="goods_name" property="goodsName"/>
    5. <result column="detail" property="detail"/>
    6. <result column="price_min" property="priceMin"/>
    7. <result column="price_max" property="priceMax"/>
    8. <result column="type_id" property="typeId"/>
    9. <result column="use_stock" property="useStock"/>
    10. <result column="type_name" property="typeName"/>
    11. <collection property="specs" ofType="com.cc.shoppingmall.pojo.vo.goods.GoodsDetailWx$Spec"
    12. javaType="java.util.List" select="getSpec" column="id">
    13. </collection>
    14. </resultMap>
    15. <resultMap id="specs" type="com.cc.shoppingmall.pojo.vo.goods.GoodsDetailWx$Spec">
    16. <result column="specId" property="id"/>
    17. <result column="price" property="price"/>
    18. <result column="stockNum" property="stockNum"/>
    19. <result column="title" property="title"/>
    20. </resultMap>
    21. <select id="selectPageForWechatByGoodsType" resultMap="GoodsList">
    22. select g.id,
    23. g.goods_image,
    24. g.goods_name,
    25. g.detail,
    26. g.price_min,
    27. g.price_max,
    28. gt.id type_id,
    29. g.use_stock,
    30. gt.type_name
    31. from goods_cash_conf conf
    32. inner join goods g on conf.goods_id = g.id
    33. inner join goods_type gt on conf.type_id = gt.id
    34. where gt.id = #{typeId}
    35. <if test="goodsName != null and goodsName != ''">
    36. and g.goods_name like concat(concat("%", #{goodsName}), "%")
    37. </if>
    38. and conf.status = 1
    39. and g.show_wechat = 1
    40. and conf.is_delete = 0
    41. and g.is_delete = 0
    42. and gt.is_delete = 0
    43. order by gt.ord asc, g.ord asc, g.create_time desc,g.id desc
    44. </select>
    45. <select id="getSpec" parameterType="string" resultMap="specs">
    46. select gs.id specId, gs.price, gs.stock stockNum, gs.specification_name title
    47. from goods_specification gs
    48. where gs.is_delete = 0 and gs.goods_id = #{id}
    49. </select>