PageHelper.startPage(Integer.parseInt(params.get("pageNo").toString()), Integer.parseInt(params.get("pageSize").toString()));
注意:一定是得放在xxxxMapper.xxxxxx上面。
参数:
reasonable:
禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据
启用合理化时,如果pageNum<1会查询第一页,如果pageNum>pages会查询最后一页
pageSizeZero:
设置为true时,如果pageSize=0或者RowBounds.limit = 0就会查询出全部的结果(相当于没有执行分页查询,但是返回结果仍然是Page类型)
例:
logger.info("params:"+params);
PageHelper.startPage(Integer.parseInt(params.get("pageNo").toString()), Integer.parseInt(params.get("pageSize").toString()));
List<InsuranceOther> list=insuranceOtherMapper.getInsuranceOtherList(params);
PageInfo<InsuranceOther> orderVoPageInfo = new PageInfo<>(list);
再注意:如果是一对多的SQL,以上方式是不对的。(这种情况,如果'从表'没有数据,返回的分页数量也不对,处理办法是主表分页的时候添加条件)
一对多的SQL处理示例:
<!--获取产品列表 -->
<select id="getProductList" parameterType="java.util.Map" resultMap="InsuranceProductVo">
SELECT
<include refid="Vo_Column_List"></include>
FROM
insurance_product pro
LEFT JOIN insurance_clause cla ON pro.id = cla.product_id
<where>
<!--先按主表分页,不然返回给前端的每页数量不是pageSize数量-->
pro.id IN (SELECT ip.id FROM (
SELECT id FROM insurance_product WHERE 1 = 1
AND id IN (SELECT DISTINCT product_id FROM `insurance_clause`) <!-这个条件处理从表没有造成分页数量不对的情况-->
<if test="merchantId != null">
and merchant_id = #{merchantId}
</if>
<if test="start !=null">
LIMIT ${start},${pageSize}
</if>
) AS ip
)
and cla.is_delete = 0
ORDER BY (CASE
WHEN pro.platform = 2 THEN 1 <!--象保保2排最前面-->
WHEN pro.platform = 3 THEN 2 <!--象保保&大象保险3排第二-->
WHEN pro.platform = 1 THEN 3 <!--大象保险1排第三-->
ELSE 4 END) <!--中保协4排最后-->
</where>