刚才使用mybatisplus提供的Page分页时,一直失效,看网上说要加配置什么的,试了多种方案还是不行。最后自己结合github pagehelper实现了分页,目前还不知道有没有其他影响。我使用的是springboot项目,下面就开始编码吧。
一、环境搭建springboot:2.0.6.RELEASE
mybatis-plus-status:3.4.2
pagehelper:1.3.0
二、配置类com.longfor.c2 cmo-expense 1.0.0-SNAPSHOT org.apache.velocity velocity-engine-core 2.2 com.baomidou mybatis-plus-generator 3.4.0 com.baomidou mybatis-plus-boot-starter 3.4.2 com.github.pagehelper pagehelper-spring-boot-starter 1.3.0 org.mybatis mybatis org.mybatis mybatis-spring
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
三、代码示例
LambdaQueryWrapperqueryWrapper = new LambdaQueryWrapper<>(); queryWrapper.in(Student::getId, Arrays.asList(ids)); //输入页码和页数 PageHelper.startPage(query.getPageNumber(), query.getPageSize()); List students= studentService.getBaseMapper().selectList(queryWrapper); com.github.pagehelper.PageInfo pageInfo = new com.github.pagehelper.PageInfo<>(students); //students--分页后的数据 pageInfo.getTotal()--总条数 return PageResponse.page(students, pageInfo.getTotal());



