pagehelper是一款分页插件,可以很好地集成在SpringBoot框架中,简单配置,轻松使用
首先在pom中添加依赖
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper --><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.1.4</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.2.5</version></dependency>
这样的话就可以用直接使用分页了
PageHelper.startPage(page,limit);List<HashMap<String, Object>> list = xxxBiz.selectAll();PageInfo<HashMap<String, Object>> pageInfo = new PageInfo<>(list);
想要有一下功能的话
pagehelper:helper-dialect: mysqlreasonable: truesupport-methods-arguments: trueparams: count-countSqlhelper-dialect:指定数据库,不指定的话会默认自动检测数据库类型reasonable:是否启用分页合理化。如果启用,当pagenum<1时,会自动查询第一页的数据,当pagenum>pages时,自动查询最后一页数据;不启用的,以上两种情况都会返回空数据support-methods-arguments:默认值false,分页插件会从查询方法的参数值中,自动根据上面 params 配置的字段中取值,查找到合适的值时就会自动分页。(copy来的,因为我也不知道怎么去解释)params:用于从对象中根据属性名取值, 可以配置 pageNum,pageSize,count,pageSizeZero,reasonable,不配置映射的用默认值, 默认值为pageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero
需要添加依赖
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter --><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-autoconfigure</artifactId><version>1.2.5</version></dependency>
