标签:sqlite main 数据 new lis 方言 ica postgre asp
**SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了。全部自动实现。
话不多说,直接上代码:
<!-- mybatis的分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>
注意你是配置的什么数据进行分页操作 pagehelper.helperDialect=postgresql 我这里是postgresql数据库
支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库
#pagehelper分页插件配置
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
@SpringBootApplication
//将项目中对应的mapper类的路径加进来就可以了
@MapperScan({"org.baihuida.hints.dao"})
public class CodeHintsApplication {
public static void main(String[] args) {
SpringApplication.run(CodeHintsApplication.class, args);
}
//配置mybatis的分页插件pageHelper
@Bean
public PageHelper pageHelper(){
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("offsetAsPageNum","true");
properties.setProperty("rowBoundsWithCount","true");
properties.setProperty("reasonable","true");
properties.setProperty("dialect","mysql"); //配置mysql数据库的方言
pageHelper.setProperties(properties);
return pageHelper;
}
}
@RequestMapping("queryKeywords")
public PageInfo<Keywords> queryKeywords(@RequestParam(defaultValue="1") int pageNum,
@RequestParam(defaultValue="3") int pageSize) {
PageInfo<Keywords> pageInfo = keywordsService.getLogInfoPage(pageNum,pageSize);
return pageInfo;
}
@Override
public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<Keywords> list= keywordsMapper.listKeywords();
PageInfo<Keywords> pageInfo = new PageInfo<Keywords>(list);
return pageInfo;
}
public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize);
@Override
public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<Keywords> list= keywordsMapper.listKeywords();
PageInfo<Keywords> pageInfo = new PageInfo<Keywords>(list);
return pageInfo;
}
List<Keywords> listKeywords();
<select id="listKeywords" resultType="org.baihuida.hints.entity.Keywords">
select keyword from keywords
</select>
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
标签:sqlite main 数据 new lis 方言 ica postgre asp
原文地址:https://www.cnblogs.com/jixu8/p/9410852.html