第一批本科,易佰丰,韩讯5
参看了,使用起来非常放方便,关于更多pagehelper可以点击https://github.com/pagehelper/mybatis-pagehelper。
当spring boot集成好mybatis时候需要进行分页,我们首先添加maven支持
<dependency> <groupid>com.github.pagehelper</groupid> <artifactid>pagehelper</artifactid> <version>5.1.2</version> </dependency> <dependency> <groupid>com.github.pagehelper</groupid> <artifactid>pagehelper-spring-boot-autoconfigure</artifactid> <version>1.2.3</version> </dependency> <dependency> <groupid>com.github.pagehelper</groupid> <artifactid>pagehelper-spring-boot-starter</artifactid> <version>1.2.3</version> </dependency>
方式一:我们在application.yml(spring 需要读取的yml)中加入
pagehelper: helperdialect: mysql reasonable: true supportmethodsarguments: true params: count=countsql
然后重启即可。
配置文件最终会被java所读取,最终注入到spring bean中,所以我们方法二是配置其bean类,热加载方便修改当然方式一更简单,
方式二:在注解涵盖package下面新建pageheleperconfig
import com.github.pagehelper.pagehelper; import java.util.properties; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; /** * @author zhuxiaomeng * @date 2018/1/2. * @email 154040976@qq.com */ @configuration public class pagehelperconfig { @bean public pagehelper getpagehelper(){ pagehelper pagehelper=new pagehelper(); properties properties=new properties(); properties.setproperty("helperdialect","mysql"); properties.setproperty("reasonable","true"); properties.setproperty("supportmethodsarguments","true"); properties.setproperty("params","count=countsql"); pagehelper.setproperties(properties); return pagehelper; } }
pagehelper 基础知识为:
import com.github.pagehelper.page; import com.github.pagehelper.pagehelper;
page<t> tpage= pagehelper.startpage(page,limit);
下一句的查询语句来进行分页。你只需要用list<t>接收
如果你有疑问可以下载开源项目lenos 快速开发脚手架,spring boot 版本来熟悉学习。
地址:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论