mybatisplus 自动分页 怎么关闭
时间: 2023-09-26 18:14:21 浏览: 49
在 Mybatis-Plus 中关闭自动分页可以通过设置分页插件的 `auto-dialect` 属性为 `false` 来实现。
例如,在 Spring Boot 中,可以在配置文件中添加如下配置:
```yaml
mybatis-plus:
configuration:
# 关闭自动分页
page-helper:
auto-dialect: false
```
或者在代码中手动配置:
```java
@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor interceptor = new PaginationInterceptor();
// 关闭自动分页
interceptor.setDialectType("mysql");
interceptor.setAutoDialect(false);
return interceptor;
}
}
```
相关问题
mybatisplus+分页查询
以下是使用MybatisPlus进行分页查询的示例代码:
```java
// 导入相关类
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public IPage<User> getUserListByPage(int pageNum, int pageSize) {
// 构建分页对象
Page<User> page = new Page<>(pageNum, pageSize);
// 执行分页查询
IPage<User> userIPage = userMapper.selectPage(page, null);
// 返回分页结果
return userIPage;
}
}
```
上述代码中,我们使用了MybatisPlus提供的`Page`类来构建分页对象,并将其作为参数传递给`selectPage`方法,该方法会自动进行分页查询并返回分页结果。需要注意的是,`selectPage`方法的第二个参数为查询条件,如果不需要查询条件可以传入`null`。
mybatisplus 3.5 分页查询
mybatisplus 3.5 的分页查询可以通过 Page 类来实现。具体步骤如下:
1. 创建 Page 对象,指定当前页码和每页显示的记录数。
```
Page<User> page = new Page<>(1, 10);
```
2. 调用 selectPage 方法进行分页查询,传入 Page 对象和查询条件。
```
IPage<User> userPage = userMapper.selectPage(page, new QueryWrapper<User>().eq("age", 18));
```
其中,userMapper 是 MybatisPlus 自动生成的 Mapper 接口,QueryWrapper 是 MybatisPlus 提供的查询条件构造器。
3. 从返回的 IPage 对象中获取分页信息和查询结果。
```
long total = userPage.getTotal(); // 总记录数
long current = userPage.getCurrent(); // 当前页码
long size = userPage.getSize(); // 每页显示的记录数
List<User> userList = userPage.getRecords(); // 查询结果
```