ssm下使用分页插件PageHelper进行分页
1. 导入maven依赖:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.</version>
</dependency>
2. 编写SqlConfig.xml配置文件(这个文件的名字任意)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <!-- mybatis分页插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
</configuration>
3. 编写controller方法,注意:查询的方法必须紧跟在PageHelper.startPage(pn, 10); 这条语句后面!!
/**
* 查看所有问题
*
* @param model
* @return
*/
@RequestMapping("/findAll")
public String findAll(@RequestParam(value="pn",defaultValue="1")Integer pn, Model model) {
//从第一条开始 每页查询10条数据
PageHelper.startPage(pn, 10);
List<Question> questions = questionService.findAll();
//将用户信息放入PageInfo对象里
PageInfo page = new PageInfo(questions,10);
model.addAttribute("pageInfo", page);
return "question_list";
}
4. jsp页面显示:question_list.jsp
<%--页面数据展示--%>
<div id="table-div">
<table class="table table-hover">
<c:forEach items="${pageInfo.list}" var="question" varStatus="vs">
<tr>
<td class="td1">
<a href="${pageContext.request.contextPath}/question/look?qid=${question.qid}">
<img src="${pageContext.request.contextPath}/images/question_logo.png"
style="width: 20px;height: 20px;"/> ${question.title}
</a>
<font color="red"> - [悬赏 ${question.credit} 积分] </font>
<c:if test="${question.isResolved == 1}">
(已解决)
</c:if>
</td>
<td class="td2">
<fmt:formatDate value="${question.askTime}" pattern="yyyy-MM-dd HH:mm"/>
</td>
</tr>
</c:forEach>
</table>
</div> <!-- 分页条 -->
<div id="div_pagination_bottom">
<nav aria-label="Page navigation">
<ul class="pagination">
<li>
<a href="${pageContext.request.contextPath}/question/findAll?pn=${pageInfo.pageNum-1}"
aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<c:forEach items="${pageInfo.navigatepageNums }" var="page_Num">
<c:if test="${page_Num == pageInfo.pageNum }">
<li class="active"><a href="#">${ page_Num}</a></li>
</c:if>
<c:if test="${page_Num != pageInfo.pageNum }">
<li>
<a href="${pageContext.request.contextPath}/question/findAll?pn=${ page_Num}">${ page_Num}</a>
</li>
</c:if>
</c:forEach>
<li>
<a href="${pageContext.request.contextPath}/question/findAll?pn=${pageInfo.pageNum+1}"
aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
</div>
ssm下使用分页插件PageHelper进行分页的更多相关文章
- SpringBoot 使用 MyBatis 分页插件 PageHelper 进行分页查询
前言:本文档使用的是 SpringBoot,如果是 Spring 还需要在 MyBatis 配置 xml 中配置拦截器,并且 PageHelper 是针对 MyBatis 的,MyBatis 的集成不 ...
- 基于Mybatis分页插件PageHelper
基于Mybatis分页插件PageHelper 1.分页插件使用 1.POM依赖 PageHelper的依赖如下.需要新的版本可以去maven上自行选择 <!-- PageHelper 插件分页 ...
- Java SSM框架之MyBatis3(三)Mybatis分页插件PageHelper
引言 对于使用Mybatis时,最头痛的就是写分页,需要先写一个查询count的select语句,然后再写一个真正分页查询的语句,当查询条件多了之后,会发现真不想花双倍的时间写count和select ...
- MyBatis学习总结_17_Mybatis分页插件PageHelper
如果你也在用Mybatis,建议尝试该分页插件,这一定是最方便使用的分页插件. 分页插件支持任何复杂的单表.多表分页,部分特殊情况请看重要提示. 想要使用分页插件?请看如何使用分页插件. 物理分页 该 ...
- Mybatis学习---Mybatis分页插件 - PageHelper
1. Mybatis分页插件 - PageHelper说明 如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件. 该插件目前支持Oracle,Mysql,MariaDB,S ...
- MyBatis学习总结(17)——Mybatis分页插件PageHelper
如果你也在用Mybatis,建议尝试该分页插件,这一定是最方便使用的分页插件. 分页插件支持任何复杂的单表.多表分页,部分特殊情况请看重要提示. 想要使用分页插件?请看如何使用分页插件. 物理分页 该 ...
- Mybatis的分页插件PageHelper
Mybatis的分页插件PageHelper 项目地址:http://git.oschina.net/free/Mybatis_PageHelper 文档地址:http://git.oschina. ...
- mybatis分页插件PageHelper的使用(转)
Mybatis 的分页插件PageHelper-4.1.1的使用 Mybatis 的分页插件 PageHelper 项目地址:http://git.oschina.net/free/Mybatis_P ...
- Mybatis分页插件PageHelper的配置和使用方法
Mybatis分页插件PageHelper的配置和使用方法 前言 在web开发过程中涉及到表格时,例如dataTable,就会产生分页的需求,通常我们将分页方式分为两种:前端分页和后端分页. 前端分 ...
随机推荐
- python_django_views视图模块
视图(views.py):接收web请求,并响应web请求 在视图响应web请求的过程中,响应文件可能是网页,也可能是json数据 若响应的是网页,我们可分为: 地址重定向的网页请求(子类HttpRe ...
- node-fs(1) 无法从文件流内部读取到的字符串转化成json
先上一段代码 let fs=require('fs');//引入fs模块 let blob = fs.readFileSync('/node/product1/data.txt');//读取指定目录下 ...
- 报错 DOMDocument not found
php -m 查看有没有dom扩展 没有安装扩展 yum install php-dom php 常用扩展有 yum install php-solr php-opcache php-seasLog ...
- 2019hdu第二场
10:签到求n!取模 #include <iostream> #include <iterator> #include <algorithm> typedef lo ...
- 牛客多校第三次B——线段树维护线性基交
写线性基交函数时调试了半天.. #include<bits/stdc++.h> using namespace std; #define ll long long #define maxn ...
- NXOpenC#_Training_2(cn)【转载】
- iOS之NSArray数组排序
一.数组遍历 除了常用的for和for-in遍历外,系统还提供了三种枚举遍历,对于大量的数据遍历可以使用下列三个方法. - (void)enumerateObjectsUsingBlock:(void ...
- day28-描述符应用与类的装饰器
#!/usr/bin/env python# -*- coding:utf-8 -*-# ------------------------------------------------------- ...
- 2-JDK环境变量配置和验证
背景: 官网下载,默认路径安装,如下图,java目录下有两个文件夹:jdk和jre: 1.计算机 -> 右击 -> 属性 -> 选择左侧的'高级系统设置' 2.高级系统设置 -> ...
- jQuery post使用变量作参数名
jQuery Query Post使用方法: $.post("test.php", { name: "John", time: "2pm" ...