SpringBoot如何集成PageHelper分页功能
作者:玉天恒 时间:2022-10-22 03:18:34
添加MyBatis的代码并修改以下部分:
1.添加MyBatisConfig
package myshop.config;
import java.util.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.pagehelper.PageHelper;
@Configuration
public class MyBatisConfig {
@Bean
public PageHelper pageHelper()
{
System.out.println("Use PageHelper");
PageHelper pageHelper = new PageHelper();
Properties p = new Properties();
p.setProperty("offsetAsPageNum", "true");
p.setProperty("rowBoundsWithCount", "true");
p.setProperty("reasonable", "true");
pageHelper.setProperties(p);
return pageHelper;
}
}
2.修改MyBatisController
package myshop.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import myshop.bean.UserInfo;
import myshop.service.MyBatisService;
@RestController
public class MyBatisController {
@Autowired
private MyBatisService myBatisService;
@RequestMapping("likeName")
public List<UserInfo> likeName(String username)
{
PageHelper.startPage(1,2);
return myBatisService.likeName(username);
}
}
3.访问地址
http://localhost:8080/likeName?username=天恒
来源:https://www.cnblogs.com/tianhengblogs/p/9539269.html
标签:Spring,Boot,Page,Helper,分页
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java StringBuilder和StringBuffer源码分析
2023-04-03 00:10:58
Java反射概念与使用实例代码
2022-02-24 23:55:40
Java遗传算法之冲出迷宫
2022-01-12 21:34:58
关于C++一些特性的探究
2022-04-10 07:17:54
基于WPF实现3D画廊动画效果的示例代码
2022-02-06 08:02:22
![](https://img.aspxhome.com/file/2023/4/96364_0s.png)
Java数据结构之红黑树的真正理解
2022-07-16 01:36:16
![](https://img.aspxhome.com/file/2023/9/78369_0s.png)
Android截屏保存png图片的实例代码
2022-01-26 16:10:11
IntelliJ IDEA2020.1版本更新pom文件自动导包的方法
2023-01-13 17:44:01
![](https://img.aspxhome.com/file/2023/2/101972_0s.jpg)
Java8内存模型PermGen Metaspace实例解析
2023-11-25 10:53:36
![](https://img.aspxhome.com/file/2023/8/59968_0s.jpg)
C#创建windows系统用户的方法
2022-07-16 20:30:12
快速了解c# 常量
2023-06-26 23:35:32
轻松学习C#的装箱与拆箱
2021-07-01 12:11:51
java中main函数你知道多少
2023-05-26 12:32:15
![](https://img.aspxhome.com/file/2023/1/96531_0s.png)
基于Java利用static实现单例模式
2021-12-20 06:07:32
java实现支付宝支付接口的调用
2023-10-13 09:43:40
![](https://img.aspxhome.com/file/2023/1/58611_0s.jpg)
Java8中的LocalDateTime你会使用了吗
2023-11-15 07:02:07
C# wpf使用ListBox实现尺子控件的示例代码
2023-02-23 04:43:30
![](https://img.aspxhome.com/file/2023/8/98278_0s.png)
Spring Boot集成Ehcache缓存解决方式
2023-05-13 08:27:27
Idea 快速生成方法返回值的操作
2023-07-31 02:12:49
![](https://img.aspxhome.com/file/2023/9/132039_0s.jpg)
Java CharacterEncodingFilter案例详解
2022-03-21 18:22:32
![](https://img.aspxhome.com/file/2023/0/62960_0s.png)