- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章spring boot集成pagehelper(两种方式)由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
参看了pagehelper-spring-boot,使用起来非常放方便,关于更多PageHelper可以点击https://github.com/pagehelper/Mybatis-PageHelper.
当spring boot集成好mybatis时候需要进行分页,我们首先添加maven支持 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<
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)中加入 。
1
2
3
4
5
|
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
|
然后重启即可.
配置文件最终会被java所读取,最终注入到spring bean中,所以我们方法二是配置其bean类,热加载方便修改当然方式一更简单, 。
方式二:在注解涵盖package下面新建PageHeleperConfig 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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 基础知识为:
1
2
|
import
com.github.pagehelper.Page;
import
com.github.pagehelper.PageHelper;
|
1
|
Page<T> tPage= PageHelper.startPage(page,limit);
|
下一句的查询语句来进行分页。你只需要用List<T>接收 。
如果你有疑问可以下载开源项目lenos 快速开发脚手架,spring boot 版本来熟悉学习.
地址:https://gitee.com/bweird/lenosp 。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://my.oschina.net/u/3312115/blog/1600825 。
最后此篇关于spring boot集成pagehelper(两种方式)的文章就讲到这里了,如果你想了解更多关于spring boot集成pagehelper(两种方式)的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我是一名优秀的程序员,十分优秀!