SSM使用PageHelper
第一步---->导入Maven依赖
<!--pageHelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
第二步---->在spring-mapper.xml的SqlSessionFactory中加入一下代码
<!-- 传入PageHelper的插件 -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<props>
<prop key="helperDialect">mysql</prop>
<prop key="resonable">true</prop>
</props>
</property>
</bean>
</array>
</property>
第三步---->配置实体类,serviceImp,Mapper等,查询全部分页
1
2 /** Mapper中写下page,size
3 * 查询全部学生
4 */
5 List<Student> findAll(int page, int size);
6 -----------------------------------------------------------------------------
7 /**
8 *在xxxServiceImpl中写下 PageHelper.startPage(page,size);
9 */
10 @Override
11 public List<Student> findAll(int page,int size) {
12 PageHelper.startPage(page,size);
13 return studentMapper.findAll(page, size);
14 }
第四步---->编写Controller层
1 /**
2 * 查询所有学生
3 @RequestParam(name="page",required = true,defaultValue = "1")int page,(page:第几页)
4 @RequestParam(name="size",required = true,defaultValue = "5")int size (size:几条数据)
5 * @param
6 * @return
7 */
8 @RequestMapping("/findAll")
9 public ModelAndView list(@RequestParam(name="page",required = true,defaultValue = "1")int page,
10 @RequestParam(name="size",required = true,defaultValue = "5")int size ){
11 ModelAndView mv = new ModelAndView();
12 List<Student> all = studentService.findAll(page, size);
13 //PageInfo就是一个分页Bean
14 PageInfo pageInfo =new PageInfo(all);
15 mv.addObject("pageInfo", pageInfo);
16 mv.setViewName("student/findStudentAll");//指定跳转的页面
17 return mv;
18 }
第五步---->编写JSP页面
1 <c:forEach var="student" items="${pageInfo.list}">//pageInfo是controller层存入mv中的数据,
2 <tr>
3 <td>${student.SId}</td>
4 <td>${student.SName}</td>
5 <td>${student.SBirth}</td>
6 <td>${student.SSex}</td>
7 <td>
8 <a href="${pageContext.request.contextPath}/toUpdateStudent?id=${student.getSId()}">更改</a> |
9 <a href="${pageContext.request.contextPath}/del/${student.getSId()}">删除</a>
10 </td>
11 </tr>
12 </c:forEach>
13 <ul class="pagination">
14 <li><a href="${pageContext.request.contextPath}/findAll?page=1&size=5" aria-label="Previous">首页</a></li>
15 <li><a href="${pageContext.request.contextPath}/findAll?page=${pageInfo.pageNum-1}&size=5">上一页</a></li>
16 <c:forEach begin="1" end="${pageInfo.pages}" var="pageNumber">
17 <li><a href="${pageContext.request.contextPath}/findAll?page=${pageNumber}&size=5">${pageNumber}</a></li>
18 </c:forEach>
19 <li><a href="${pageContext.request.contextPath}/findAll?page=${pageInfo.pageNum+1}&size=5">下一页</a></li>
20 <li><a href="${pageContext.request.contextPath}/findAll?page=${pageInfo.pages}&size=5" aria-label="Next">尾页</a></li>
21 </ul>
就这样SSMPageHelper结束!!!!
SSM使用PageHelper的更多相关文章
- ssm+maven+pageHelper搭建maven项目实现快速分页
ssm+maven+pageHelper搭建maven项目实现快速分页 PageHelper分页使用: 插件的环境引入: 1.pom文件中引入分页插件的资源位置: <dependency> ...
- ssm+PageHelper实现分页查询
通过搭建ssm框架,然后通过mybatis的分页插件pagehelp进行分页查询.源码:https://gitee.com/smfx1314/pagehelper 看一下项目结构: 首先创建一个mav ...
- 关于在SSM框架下使用PageHelper
首先,如果各位在这块配置和代码有什么问题欢迎说出来,我也会尽自己最大的能力帮大家解答 这些代码我都是写在一个小项目里的,项目的github地址为:https://github.com/Albert-B ...
- PageHelper分页实战(SSM整合)
步骤一:引入SSM相关的jar包,包列表如下: 步骤二:创建或修改配置文件,配置文件清单如下: applicationContext.xml <?xml version="1.0&qu ...
- SSM框架手动实现分页逻辑(非PageHelper)
第一种方法:查询出所有数据再分页 分析: 分页时,需要获得前台传来的两个参数,分别为pageNo(第几页数据),pageSize(每页的条数); 根据这两个参数来计算出前端需要的数据是查出数据list ...
- SSM手动实现分页逻辑---非PageHelper方式
第一种方法:查询出所有数据再分页 分析: 分页时,需要获得前台传来的两个参数,分别为pageNo(第几页数据),pageSize(每页的条数); 根据这两个参数来计算出前端需要的数据是查出数据list ...
- 后端分页神器,mybatis pagehelper 在SSM与springboot项目中的使用
mybatis pagehelper想必大家都耳熟能详了,是java后端用于做分页查询时一款非常好用的分页插件,同时也被人们称为mybatis三剑客之一,下面 就给大家讲讲如何在SSM项目和sprin ...
- ssm工程集成mybatis分页插件pagehelper
1 首先需要在mybatis的配置文件SqlMapConfig.xml文件中配置pagehelper插件 <plugins> <plugin interceptor=" ...
- Java SSM框架之MyBatis3(三)Mybatis分页插件PageHelper
引言 对于使用Mybatis时,最头痛的就是写分页,需要先写一个查询count的select语句,然后再写一个真正分页查询的语句,当查询条件多了之后,会发现真不想花双倍的时间写count和select ...
- SSM+PageHelper+jqGrid实现数据分页
前言 前几天自己写了一个分页功能,代码逻辑写的很乱今天发现jqGrid这个工具是真好用,故记录下来方便以后使用首先是PageHelper后台分页工具PageHelper的原理是基于拦截器实现的 具体流 ...
随机推荐
- Vue ref 和 v-for 结合(ref 源码解析)
前言 Vue 中组件的使用很方便,而且直接取组件实例的属性方法等也很方便,其中通过 ref 是最普遍的. 平时使用中主要是对一个组件进行单独设置 ref ,但是有些场景下可能是通过给定数据渲染的,这时 ...
- Archlinux配置fcitx5
fcitx5--Linux中最好用的中文输入法 ArchLinux配置fcitx5 输入法 本文基于archlinux + dwm.其他的桌面环境以及窗口管理器,配置选项差不多. 安装基础包 fcit ...
- Java安全之Resin2内存马
Java安全之Resin2内存马 环境 resin2.1.17 添加Filter分析 依然是web.xml注册一个filter,debug进去看注册流程 debug dofilter逻辑时看到如下代码 ...
- Java安全之反序列化(1)
序列化与反序列化 概述 Java序列化是指把Java对象转换为字节序列的过程:这串字符可能被储存/发送到任何需要的位置,在适当的时候,再将它转回原本的 Java 对象,而Java反序列化是指把字节序列 ...
- Spring Boot 中使用 tkMapper
说明:基于 MyBatis 有很多第三方功能插件,这些插件可以完成数据操作方法的封装.数据库逆向工程的生成等. tkMapper 和 MyBatis-plus 都是基于 MyBatis 提供的第三方插 ...
- 对比entrypoint以及cmd
如何查看 现有 images 的 入口信息 docker image inspect image_id { "entrypoint": "xxx" " ...
- 【Azure API 管理】Azure APIM服务集成在内部虚拟网络后,在内部环境中打开APIM门户使用APIs中的TEST功能失败
问题描述 使用微软API管理服务(Azure API Management),简称APIM. 因为公司策略要求只能内部网络访问,所以启用了VNET集成.集成方式见: (在内部模式下使用 Azure A ...
- SQL Server 读写分离配置的一些问题
1,新建发布服务器遇到此服务器上未安装复制组件 先执行以下sql use mastergoselect @@servername;select serverproperty('servername') ...
- UBOOT编译--- UBOOT的顶层config.mk(五)
1. 前言 UBOOT版本:uboot2018.03,开发板myimx8mmek240. 2. 概述 此文件包含在 ./Makefile 和 spl/Makefile 中. 清理状态以避免添加两次相同 ...
- 多点DMALL × Apache Kyuubi:构建统一SQL Proxy探索实践
伴随着国家产业升级的推进和云原生技术成熟,多点 DMALL 大数据技术也经历了从存算一体到存算分离的架构调整变迁.本文将从引入 Kyuubi 实现统一 SQL Proxy 的角度讲述这一探索实践的历程 ...