mybatisplus自定义分页方法
时间: 2023-08-22 14:10:49 浏览: 110
自定义分页方法需要在Mapper接口中声明方法,并在对应的XML文件中配置SQL语句。以下是使用Mybatis Plus自定义分页方法的示例:
在Mapper接口中声明方法:
```java
List<GoodsItem> selectCustomPage(IPage<GoodsItem> page, @Param("condition") GoodsCondition goodsCondition);
```
在XML文件中配置SQL语句:
```xml
<select id="selectCustomPage" parameterType="map" resultMap="goodsItemResultMap">
SELECT * FROM goods
<where>
<!-- 根据条件筛选 -->
<if test="condition != null">
<!-- 添加条件 -->
</if>
</where>
<!-- 添加排序 -->
<if test="page.sort != null">
ORDER BY ${page.sort}
</if>
LIMIT #{page.offset}, #{page.size}
</select>
```
然后,在调用该方法时,可以通过传入IPage对象来进行分页查询:
```java
IPage<GoodsItem> page = new Page<>();
page.setCurrent(currentPage); // 设置当前页码
page.setSize(pageSize); // 设置每页记录数
goodsMapper.selectCustomPage(page, goodsCondition); // 调用自定义分页方法
```
以上示例代码中,通过自定义的selectCustomPage方法实现了自定义分页查询,并且根据传入的GoodsCondition对象对查询结果进行筛选。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [MyBatisPlus XML 自定义分页](https://blog.csdn.net/lianghecai52171314/article/details/121734061)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [多表查询 Mybatis Plus 自定义方法实现分页](https://blog.csdn.net/liuerchong/article/details/124666202)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [mybatis-plus 自定义分页](https://blog.csdn.net/qq_43047126/article/details/124248572)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文