之前使用tkmybatis时候的分页代码
final Integer pageNum = parameter.getPageNum(); final Integer pageSize = parameter.getPageSize(); final Map<String, Object> map = objectToMap(parameter); PageHelper.startPage(Optional.ofNullable(pageNum).orElse(1), Optional.ofNullable(pageSize).orElse(15)); Page<TenantDTO> page = baseMapper.queryPage(map);
返回结果
{ "list":[...] , "total": 1, "pageSize": 15, "pageNum": 1 }
之前的maven依赖
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.3.0</version> <exclusions> <exclusion> <artifactId>mybatis</artifactId> <groupId>org.mybatis</groupId> </exclusion> </exclusions> </dependency>
解决方法
mybatis-plus中的依赖
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.2.0</version> </dependency> <dependency>
新增Configuration配置
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; @Configuration @EnableTransactionManagement @MapperScan("com.h2.*.*.mapper*") public class MybatisPlusConfiguration { /*** * 兼容PageHelper分页插件,防止出现page.getPageNum,page.getTotal,page.getSize都返回0 * https://blog.csdn.net/u012280292/article/details/99678037 * @return */ @Bean ConfigurationCustomizer mybatisConfigurationCustomizer() { return configuration -> configuration.addInterceptor(new PageInterceptor()); } }
解决方法转载自:https://blog.csdn.net/u012280292/article/details/99678037
本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。