SSM框架使用分页插件显示信息

1、在该SSM工程的pom.xml中加入PageHelper的分页插件依赖(若是版本号不对,可以尝试修改一下)

 1 <!-- 分页插件 -->
 2     <dependency>
 3         <groupId>com.github.miemiedev</groupId>
 4         <artifactId>mybatis-paginator</artifactId>
 5         <version>1.2.15</version>
 6     </dependency>
 7     <dependency>
 8         <groupId>com.github.pagehelper</groupId>
 9         <artifactId>pagehelper</artifactId>
10         <version>3.4.2-fix</version>
11     </dependency>

2、在myBatis的配置文件中(SqlMapConfig.xml)加入分页插件的依赖:(下面这是SqlMapConfig.xml中的全部内容)

 

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE configuration
 3   PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 4   "http://mybatis.org/dtd/mybatis-3-config.dtd">
 5 <configuration>
 6 
 7     <!-- 配置分页插件 -->
 8     <plugins>
 9         <plugin interceptor="com.github.pagehelper.PageHelper">
10             <!-- 设置数据库类型 Oracle,Mysql,MariaDB(mysql分支),SQLite,Hsqldb,PostgreSQL六种数据库-->        
11             <property name="dialect" value="mysql"/>
12         </plugin>
13     </plugins>
14 </configuration>

 

3、在spring整合文件(xml)中加入下面这句话:

1 <!-- 加载mybatis的全局配置文件 -->
2         <property name="configLocation" value="classpath:SqlMapConfig.xml" />

别忘加对Maven工程进行Maven install!!!!!!

4、ServiceImpl(此处我的EUDataGridResult是我返回给前台的一个实体类,把list集合封装起来了)

 

EUDataGridResult:

5、Controller

6、我前台测试代码,界面比较丑,人家是用异步Ajax请求,我就简单模拟了一下:

页面:

7、结果如下:(我总共有十条数据,查询第三页,每页有四条数据)

 

posted @ 2018-08-10 16:15  没有名字~  阅读(325)  评论(0编辑  收藏  举报