mybatisplus pagehelper
时间: 2023-05-10 19:51:03 浏览: 71
MybatisPlus是一个优秀的Mybatis增强工具库,提供了很多便捷的功能。其中PageHelper是其中一个常用的插件,主要用于分页查询。
使用PageHelper,可以很方便地实现分页查询。它提供了startPage方法用于设置分页信息,如当前页码和每页显示数量。同时,PageHelper会在查询语句后自动添加limit语句,从而实现分页。
除了分页功能外,PageHelper还提供了很多其他功能,如排序、过滤等。通过调用PageHelper的静态方法,可以很方便地实现这些功能。
使用PageHelper的好处不仅仅在于它提供了方便的分页功能,还在于它能够提高查询效率。PageHelper底层使用了拦截器技术,在查询过程中自动生成了一个SQL执行计划,从而减少了数据库查询的次数,提高了查询效率。
总结来说,MybatisPlus中的PageHelper插件提供了方便的分页查询功能,并且可以有效提高查询效率。在实际开发中,建议使用MybatisPlus和PageHelper来简化数据库操作,提高开发效率。
相关问题
springboot mybatisplus pagehelper整合
Spring Boot 可以很容易地与 MyBatis-Plus 和 PageHelper 整合。
首先,需要在 `pom.xml` 文件中添加以下依赖:
```xml
<!-- MyBatis-Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
<!-- PageHelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
```
接下来,在 Spring Boot 的配置文件 `application.yml` 中配置 MyBatis-Plus 和 PageHelper:
```yaml
mybatis-plus:
configuration:
# 驼峰命名转换
map-underscore-to-camel-case: true
# 打印 SQL
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
```
然后,在 MyBatis 的 Mapper 接口中,可以使用 PageHelper 进行分页查询:
```java
@Mapper
public interface UserMapper extends BaseMapper<User> {
@Select("select * from user")
List<User> list(Page<User> page);
}
```
最后,在 Service 层中调用 Mapper 方法即可实现分页查询:
```java
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public PageInfo<User> list(int pageNum, int pageSize) {
Page<User> page = PageHelper.startPage(pageNum, pageSize);
List<User> userList = userMapper.list(page);
return new PageInfo<>(userList);
}
}
```
这样,就实现了 Spring Boot、MyBatis-Plus 和 PageHelper 的整合。
mybatisplus集成pagehelper
MybatisPlus是一个基于Mybatis的增强工具,它可以简化Mybatis的开发流程,提高开发效率。而PageHelper是一个Mybatis分页插件,可以帮助我们快速实现分页功能。将PageHelper集成到MybatisPlus中,可以让我们更加方便地实现分页功能。具体步骤如下:
1. 在pom.xml文件中添加pagehelper-spring-boot-starter依赖。
2. 在application.yml文件中添加pagehelper配置。
3. 在需要分页的方法中调用PageHelper.startPage方法即可实现分页。
引用中的配置就是一个示例,其中propertyName和propertyValue是PageHelper的配置参数,reasonable表示是否合理化分页参数,默认为false,defaultCount表示是否开启默认的count查询,即在查询总数时是否使用count函数,默认为true。在集成MybatisPlus时,我们只需要按照上述步骤进行配置即可。同时,引用中的官方文档也提供了更加详细的配置说明和使用方法。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)