在
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)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/sqlbc/30720.html