同样PageHelper也可以用
PageHelper
@Configuration
@MapperScan("startDemo.mapper")
public class MybatisPlusConfig {
/**
* 新的分页插件,一缓和二缓遵循mybatis的规则
* ,需要设置
* MybatisConfiguration#useDeprecatedExecutor = false
* 避免缓存出现问题(该属性会在旧插件移除后一同移除)
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
// @Bean
// public ConfigurationCustomizer configurationCustomizer() {
// return configuration -> configuration.setUseDeprecatedExecutor(false);
// }
}
添加依赖
<!-- MyBatisX插件 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
Controller层实例
@RequestMapping("/findMember")
public Result<?> findMember(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize){
IPage<Member> ipage= memberService.findMember
(new Page<Member>(pageNum,pageSize), null);
return Result.success(ipage);
//调用的Mapper返回值也是Ipage<实体类>
//IPage<Member> findMember(Page<?> page, Integer state);
}
Mapper层需要继承BaseMapper
@Mapper
public interface CylindersMapper extends BaseMapper {
@Select("SELECT * FROM gas_bottle ORDER BY end_time DESC")
public List<Gas_bottle> selectAll();
@Select("SELECT * FROM cylinder")
IPage<Cylinder> getAllCylinders(Page<Cylinder> page, String state);
}