项目中使用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_namefrom goods_cash_conf confinner join goods g on conf.goods_id = g.idinner join goods_type gt on conf.type_id = gt.idwhere gt.id = #{typeId}<if test="goodsName != null and goodsName != ''">and g.goods_name like concat(concat("%", #{goodsName}), "%")</if>and conf.status = 1and g.show_wechat = 1and conf.is_delete = 0and g.is_delete = 0and gt.is_delete = 0order 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 titlefrom goods_specification gswhere gs.is_delete = 0 and gs.goods_id = #{id}</select>
