MyBatisPlus XML 自定义分页

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

@Mapper

public interface GoodsMapper extends BaseMapper {

/**

  • 根据条件分页查询

  • @param page

  • @param goodsCondition

  • @return

*/

IPage selectPage(IPage page, @Param(“condition”) GoodsCondition goodsCondition);

}

注意:方法的返回值为IPage对象,只有这样,在使用时,查询出来的结果才会自动赋值给IPage对象。参看下面的测试方法。

映射文件


<?xml version="1.0" encoding="UTF-8"?>

id, name, barcode, price1, price2, amount, img, pics, category_id, country_id,

addr, sell_point, priority, status, create_time, update_time

select

from tb_goods

and id = #{condition.id,jdbcType=BIGINT}

and name = #{condition.name,jdbcType=VARCHAR}

and barcode = #{condition.barcode,jdbcType=VARCHAR}

and price1 = #{condition.price1,jdbcType=DECIMAL}

and price2 = #{condition.price2,jdbcType=DECIMAL}

and amount = #{condition.amount,jdbcType=INTEGER}

and category_id = #{condition.categoryId,jdbcType=INTEGER}

and country_id = #{condition.countryId,jdbcType=INTEGER}

and addr = #{condition.addr,jdbcType=VARCHAR}

and sell_point = #{condition.sellPoint,jdbcType=VARCHAR}

and status = #{condition.status,jdbcType=INTEGER}

and create_time between #{condition.start,jdbcType=TIMESTAMP} and #{condition.end,jdbcType=TIMESTAMP}

知其然不知其所以然,大厂常问面试技术如何复习?

1、热门面试题及答案大全

面试前做足功夫,让你面试成功率提升一截,这里一份热门350道一线互联网常问面试题及答案助你拿offer

2、多线程、高并发、缓存入门到实战项目pdf书籍

3、文中提到面试题答案整理

4、Java核心知识面试宝典

覆盖了JVM 、JAVA集合、JAVA多线程并发、JAVA基础、Spring原理、微服务、Netty与RPC、网络、日志、Zookeeper、Kafka、RabbitMQ、Hbase、MongoDB 、Cassandra、设计模式、负载均衡、数据库、一致性算法 、JAVA算法、数据结构、算法、分布式缓存、Hadoop、Spark、Storm的大量技术点且讲解的非常深入


《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
(img-fqBoIY2R-1714516902280)]

[外链图片转存中…(img-R1IMzoQR-1714516902280)]
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

  • 13
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
定义分页方法需要在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 ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值