参考: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