当spring boot集成好mybatis时候需要进行分页,我们首先添加maven支持
com.github.pagehelperpagehelper5.1.2com.github.pagehelperpagehelper-spring-boot-autoconfigure1.2.3com.github.pagehelperpagehelper-spring-boot-starter1.2.3
方式一:我们在application.yml(spring 需要读取的yml)中加入
pagehelper: helperDialect:mysql reasonable:true supportMethodsArguments:true params:count=countSql
然后重启即可。
配置文件最终会被java所读取,最终注入到spring bean中,所以我们方法二是配置其bean类,热加载方便修改当然方式一更简单,
方式二:在注解涵盖package下面新建PageHeleperConfig
importcom.github.pagehelper.PageHelper;importjava.util.Properties;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;/**
* @author zhuxiaomeng
* @date 2018/1/2.
* @email 154040976@qq.com
*/@ConfigurationpublicclassPageHelperConfig{@BeanpublicPageHelpergetPageHelper(){ PageHelper pageHelper=newPageHelper(); Properties properties=newProperties(); properties.setProperty("helperDialect","mysql"); properties.setProperty("reasonable","true"); properties.setProperty("supportMethodsArguments","true"); properties.setProperty("params","count=countSql"); pageHelper.setProperties(properties);returnpageHelper; }}
pageHelper 基础知识为:
importcom.github.pagehelper.Page;importcom.github.pagehelper.PageHelper;
Page tPage= PageHelper.startPage(page,limit);
下一句的查询语句来进行分页。你只需要用List接收