mybatis-plus 分页

参考:https://blog.csdn.net/FansUnion/article/details/89192879

一、MybatisPlus自带,官网例子,自定义xml分页,麻烦的地方是 需要用 @param表示下

public interface UserMapper{//可以继承或者不继承BaseMapper
/**
 * <p>
 * 查询 : 根据state状态查询用户列表,分页显示
 * 注意!!: 如果入参是有多个,需要加注解指定参数名才能在xml中取值
 * </p>
 *
 * @param page 分页对象,xml中可以从里面进行取值,传递参数 Page 即自动分页,必须放在第一位(你可以继承Page实现自己的分页对象)
 * @param state 状态
 * @return 分页对象
 */
IPage<User> selectPageVo(Page page, @Param("state") Integer state);
}

1.service层

@Override
public PageResult<InspectionEquipmentDO> getInspectionEquipmentPage(InspectionEquipmentPageReqVO pageReqVO) {
    Page page=new Page();
    page.setCurrent(pageReqVO.getPageNo());
    page.setSize(pageReqVO.getPageSize());
    IPage<InspectionEquipmentDO> iPage = inspectionEquipmentMapper.inspectionEquipmentList(page,pageReqVO);

    PageResult<InspectionEquipmentDO> pageResult = new PageResult<>();
    pageResult.setList(iPage.getRecords());
    pageResult.setTotal( page.getTotal());

    return pageResult;
}

2.mapper.java

/**
* 查询列表
* @param reqVO
* @return
*/
IPage<InspectionEquipmentDO> inspectionEquipmentList(Page page,@Param("reqVo") InspectionEquipmentPageReqVO reqVO);

3.mapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.ly.dal.mysql.inspectionEquipment.InspectionEquipmentMapper">
    
    <select id="inspectionEquipmentList" resultType="cn.iocoder.yudao.module.ly.dal.dataobject.inspectionEquipment.InspectionEquipmentDO">
        select
            *
        from
             ly_inspection_equipment
        <where>
            <if test="reqVo.equipNumber!=null and reqVo.equipNumber!=''">
                and equip_number=#{reqVo.equipNumber}
            </if>
        </where>
    </select>
</mapper>

4.MybatisPlus分页查询+排序(order by)多次查到部分相同数据的问题

https://mzzckj.com/2022/07-12/ck-4
一般在排序后面加上 id desc
如:ORDER BY matnr DESC , id DESC

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值