mybatis-pageHelper做分页
Mybatis-PageHelpera是一个很好的第三方分页插件,支持很多数据库,几乎主流的数据库都支持
github地址:https://github.com/pagehelper/Mybatis-PageHelper
oschina地址:https://gitee.com/free/Mybatis_PageHelper
下面我们几尝试的使用一下这个分页插件吧
引入第三方jar
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
在application.xml 写拦截配置
<bean id="demoSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--dataSource属性指定要用到的连接池-->
<property name="dataSource" ref="dataSource"/>
<!--configLocation属性指定mybatis的核心配置文件-->
<property name="configLocation" value="classpath:configuration.xml"/>
<property name="mapperLocations" value="classpath:com/yihaomen/mybatis/model/*.xml"/>
<property name="typeAliasesPackage" value="com.yihaomen.mybatis.model" />
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value>
helperDialect=mysql
reasonable=true
supportMethodsArguments=true
params=count=countSql
autoRuntimeDialect=true
</value>
</property>
</bean>
</array>
</property>
</bean>
3.写controller层
@RequestMapping("/pageList")
public ModelAndView pageUserList(ModelAndView mv,
@RequestParam(required = true, defaultValue = "1") Integer pageNum,
@RequestParam(required = true, defaultValue = "3") Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Article> list = articleService.getAllArticles();
PageInfo<Article> pageInfo = new PageInfo<Article>(list);
mv.addObject("list", list);
mv.addObject("page", pageInfo);
mv.setViewName("list2");
return mv;
}
4. 写页面list2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>article list</title>
</head>
<body>
<c:forEach items="${list}" var="item">
${item.id }--${item.title }--${item.content }<br />
</c:forEach>
<br/>
<a href="/user/pageList?pageNum=${page.prePage}">上一页</a>
<a href="/user/pageList?pageNum=${page.nextPage}">下一页</a>
</body>
</html>
mybatis-pageHelper做分页的更多相关文章
- SpringBoot+Mybatis+PageHelper实现分页
SpringBoot+Mybatis+PageHelper实现分页 mybatis自己没有分页功能,我们可以通过PageHelper工具来实现分页,非常简单方便 第一步:添加依赖 <depend ...
- Python分页转Mybatis pagehelper格式分页
最近工作里遇到一个需求要把之前用Java写的一个http接口替换成用Python写的,出参是带了mybatis pageHelper中PageInfo信息的一个JSON串,而Python这边分页不会涉 ...
- MyBatis+PageHelper实现分页
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7256105.html 前面讲到Spring+SpringMVC+MyBatis深入学习及搭建(十七)--Sp ...
- SpringBoot+Mybatis+PageHelper简化分页实现
前言 经过一段时间的测试和修改PageHelper插件逐渐走到了让我觉得靠谱的时候,它功能的就是简化分页的实现,让分页不需要麻烦的多写很多重复的代码. 已经加入我的github模版中:https:// ...
- spring-boot + mybatis +pagehelper 使用分页
转自:https://segmentfault.com/a/1190000015668715?utm_medium=referral&utm_source=tuicool 最近自己搭建一个sp ...
- SpringBoot 整合Mybatis + PageHelper 实现分页
前言: 现在公司大多数都实现了前后端分离,前端使用Vue.React.AngularJS 等框架,不用完全依赖后端.但是如果对于比较小型的项目,没必要前后端分离,而SpringBoot也基本抛弃了Js ...
- mybatis如何做分页处理
1.首先根据自己实际需求编写实体类 import java.io.Serializable; public class User implements Serializable{ //最好将该实体类序 ...
- 后端分页神器,mybatis pagehelper 在SSM与springboot项目中的使用
mybatis pagehelper想必大家都耳熟能详了,是java后端用于做分页查询时一款非常好用的分页插件,同时也被人们称为mybatis三剑客之一,下面 就给大家讲讲如何在SSM项目和sprin ...
- Mybatis下collections使用pageHelper进行分页
pageHelper在对mybatis一对多分页时造成查询总页数结果不对的情况. 可以做出如下修改: service层: public CommonResult worksList(String us ...
- SpringBoot集成Mybatis并具有分页功能PageHelper
SpringBoot集成Mybatis并具有分页功能PageHelper 环境:IDEA编译工具 第一步:生成测试的数据库表和数据 SET FOREIGN_KEY_CHECKS=0; ...
随机推荐
- AIO5凭证性质设置接收下/上差(%),但是订单操作不起效。
问题: AIO5凭证性质设置接收下/上差(%),但是订单操作不起效. 例如: 现在采购订单下了200个,我想限制收货只能收两百以内. 在在线帮助上看到有接收下/上差(%)字段可以进行限制,但是在凭证性 ...
- 【转】Appium的安装-Mac平台(命令行 dmg)
其实Appium的安装方式主要有两种: 1)自己安装配置nodejs的环境,然后通过npm进行appium的安装 2)直接下载官网提供的dmg进行安装,dmg里面已经有nodejs的环境和appium ...
- 【转】JavaWeb编码之get方式中文乱码问题
一.现象描述 以get方式提交含中文表单,后台接收为乱码: <form action="admin/User/searchUser.do" method="get& ...
- windbg指定SOS版本,执行扩展命令报错
调试dump文件,加载相匹配版本的sos/clr时,绝大多数都是可以正常使用的. 然而凡事都有例外,今天在做类似工作时,遇到了错误: CLRDLL: Consider using ".cor ...
- BZOJ 1303: [CQOI2009]中位数图【前缀和】
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2737 Solved: 1698[Submit][Statu ...
- [51nod1291]Farmer
用单调栈的话不严格的O(n^3)可以轻松艹过去,统计的时候要差分. 可以发现,对于一个单调栈里的元素,从它进栈到出栈都会重复类似的计算..再差分一波后就可以只在出栈的时候计算一下了. 具体的话看代码吧 ...
- [bzoj2288][POJ Challenge]生日礼物
用堆维护双向链表来贪心... 数据范围显然不容许O(nm)的傻逼dp>_<..而且dp光是状态就n*m个了..显然没法优化 大概就会想到贪心乱搞了吧...一开始想贪心地通过几段小的负数把正 ...
- Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...
- const类型变量的详细解读
const类型变量--------------------------------------int i;const int *p; --------------------------------- ...
- Kafka监控安装
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...