当前位置:网站首页 > SQL数据库编程 > 正文

yml文件配置mysql(yml文件配置mybatis)

在

Spring Boot

集成最新版的

Mybatis-Plus

分页查询,需要进行以下步骤:

1. 引入

Mybatis-Plus

的分页插件

 <dependency> <groupId>com.baomidou</groupId> <artifactId> mybatis-plus - boot -starter</artifactId> <version>3.4.3.1</version> </dependency> 

2. 在

配置文件

进行

配置
 yaml mybatis-plus : mapper-locations: classpath*:mapper//*.xml configuration: map-underscore-to-camel-case: true log-impl: org.apache.ibatis.logging.stdout.StdOutImpl global-config: db-config: id-type: auto field-strategy: not_null table-prefix: t_ page-params: limit: 10 max-limit: 100 

,`mapper-locations`

配置

了 Mapper 文件的地址,`configuration`

配置

Mybatis

的全局

配置

,`global-config`

配置

Mybatis-Plus

的全局

配置

,`page-params`

配置

了分页参数的默认值。

3. 在 Mapper 接口

添加分页方法

 public interface UserMapper extends BaseMapper<User> {  List<User> selectUserPage(Page<User> page, @Param("name") String name); } 

4. 在 Service 层

调用分页方法进行查询

 @Service public class UserServiceImpl implements UserService {  @Autowired private UserMapper userMapper;  @Override public Page<User> selectUserPage(int pageNum, int pageSize, String name) { Page<User> page = new Page<>(pageNum, pageSize); userMapper.selectUserPage(page, name); return page; } } 

,`pageNum` 为当前页码,`pageSize` 为每页显示的数据量,`name` 为查询条件。分页查询将返回一个 `Page` 对象,其

包含了当前页码、每页显示的数据量、总数据量等信息,以及查询到的数据列表。

到此这篇yml文件配置mysql(yml文件配置mybatis)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • pymysql下载安装(pymysql模块下载)2025-04-29 23:09:09
  • mysql查看主键索引(mysql主键索引类型)2025-04-29 23:09:09
  • sql文件(sql文件怎么导入mysql)2025-04-29 23:09:09
  • sql文件转csv文件(sqlserver导出csv文件)2025-04-29 23:09:09
  • druid监控页面打不开(druid监控sql不出现)2025-04-29 23:09:09
  • Sqlldr多字节字符错误(sqlldr字段长度超过255)2025-04-29 23:09:09
  • sql里面循环执行sql(sql循环函数)2025-04-29 23:09:09
  • mysql主键和外键的建立在哪里(mysql 主键和外键)2025-04-29 23:09:09
  • mysql主键用uuid(mysql 主键)2025-04-29 23:09:09
  • 创建数据库db_shop(创建数据库db_students的SQL命令)2025-04-29 23:09:09
  • 全屏图片