项目中使用PageHelper进行分页查询的时候,发现分页有问题:每页显示的数量与传入的limit的参数不一致。
细细查看之后,发现是由于查询SQL是一对多查询,才会出现这样的问题。在网上查找了一些解决方案后,最终解决了,下面是整个查找问题、解决问题的记录。
<resultMap id="GoodsList" type="com.cc.shoppingmall.pojo.vo.goods.GoodsDetailWx">
<id column="id" property="id"/>
<result column="goods_image" property="goodsImage"/>
<result column="goods_name" property="goodsName"/>
<result column="detail" property="detail"/>
<result column="price_min" property="priceMin"/>
<result column="price_max" property="priceMax"/>
<result column="type_id" property="typeId"/>
<result column="use_stock" property="useStock"/>
<result column="type_name" property="typeName"/>
<collection property="specs" ofType="com.cc.shoppingmall.pojo.vo.goods.GoodsDetailWx$Spec"
javaType="java.util.List" select="getSpec" column="id">
</collection>
</resultMap>
<resultMap id="specs" type="com.cc.shoppingmall.pojo.vo.goods.GoodsDetailWx$Spec">
<result column="specId" property="id"/>
<result column="price" property="price"/>
<result column="stockNum" property="stockNum"/>
<result column="title" property="title"/>
</resultMap>
<select id="selectPageForWechatByGoodsType" resultMap="GoodsList">
select g.id,
g.goods_image,
g.goods_name,
g.detail,
g.price_min,
g.price_max,
gt.id type_id,
g.use_stock,
gt.type_name
from goods_cash_conf conf
inner join goods g on conf.goods_id = g.id
inner join goods_type gt on conf.type_id = gt.id
where gt.id = #{typeId}
<if test="goodsName != null and goodsName != ''">
and g.goods_name like concat(concat("%", #{goodsName}), "%")
</if>
and conf.status = 1
and g.show_wechat = 1
and conf.is_delete = 0
and g.is_delete = 0
and gt.is_delete = 0
order by gt.ord asc, g.ord asc, g.create_time desc,g.id desc
</select>
<select id="getSpec" parameterType="string" resultMap="specs">
select gs.id specId, gs.price, gs.stock stockNum, gs.specification_name title
from goods_specification gs
where gs.is_delete = 0 and gs.goods_id = #{id}
</select>