PageHelper5.0.0分页插件与mybatis的集成
来源:互联网 发布:网易云音乐推荐算法 编辑:程序博客网 时间:2024/06/05 05:11
PageHelper5.0.0分页插件与mybatis的集成
PageHelper作为使用最方便的分页插件,因为操作简单,深受广大编程爱好者的喜爱,那么它是怎么与mybatis进行集成的呢?
1、maven集成
<!-- pagehelper分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.0.0</version> </dependency>
2、mabatis集成,
(1) 第一种写法,spring-mybatis.xml
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 数据库连接池 --> <property name="dataSource" ref="dataSource" /> <!-- 加载mybatis的全局配置文件 --> <!-- <property name="configLocation" value="classpath:sqlMapConfig.xml" /> --> <!-- 为com.red.packet.po包下的所有实体类配置别名(mybatis 3.2.8以上版本) --> <property name="typeAliasesPackage" value="com.red.packet.po" /> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <value> helperDialect=mysql </value> </property> </bean> </array> </property> </bean>
(2)第二种写法 spring-mybatis.xml加SqlMapConfig.xml 1、spring-mybatis.xml
<!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 数据库连接池 --><property name="dataSource" ref="dataSource" /><!-- 加载mybatis的全局配置文件 --><property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" /></bean>
2、 SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration><plugins> <!-- com.github.pagehelper为PageHelper类所在包名 --> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库--> <property name="helperDialect" value="mysql"/> </plugin></plugins></configuration>
3、service层
/** * 查询商品列表并分页 */@Overridepublic EUDataGridResult getItemList(int page, int rows){TbItemExample example = new TbItemExample();//设置分页PageHelper.startPage(page, rows);//取到商品对象集合List<TbItem> list = itemMapper.selectByExample(example);//取分页信息PageInfo<TbItem> pageInfo = new PageInfo<>(list);long total = pageInfo.getTotal();//与eassyui进行集成EUDataGridResult result = new EUDataGridResult();result.setRows(list);result.setTotal(total);return result;}
4、controller层,针对的是easyui表格,因为必须返回数据格式为 {total:”2”,rows:[{“id”:”1”,”name”,”张三”},{“id”:”2”,”name”,”李四”}]}
/** * 按照easyui datagrid格式返回数据进行分页 * @param page * @param rows * @return */@RequestMapping("/item/list")@ResponseBodypublic EUDataGridResult getItemList(Integer page,Integer rows){EUDataGridResult itemList = itemService.getItemList(page, rows);return itemList;}
5、效果
阅读全文
1 0
- PageHelper5.0.0分页插件与mybatis的集成
- 使用mybatis分页插件PageHelper5.0.0遇到的问题总结
- 使用mybatis分页插件PageHelper5.0.0遇到的问题总结
- 使用mybatis分页插件PageHelper5.1.2遇到的问题
- mybatis系列五:使用pagehelper5插件进行分页
- mybaits 分页插件 pageHelper5.0.2
- mybaits 分页插件 pageHelper5.0.2
- Spring Boot集成MyBatis与分页插件
- Spring Boot集成MyBatis与分页插件
- SpringBoot集成MyBatis的分页插件PageHelper
- Mybatis集成分页插件pageHelper
- SpringBoot集成MyBatis的分页插件PageHelper(回头草)
- mybatis的分页插件
- Mybatis的分页插件
- Mybatis的分页插件
- mybatis 分页插件pagehelper集成及使用
- Spring中集成Mybatis分页插件PageHelper
- spring boot和mybatis集成分页插件
- BZOJ 2744 浅谈异或二进制分析及二分图最大团
- array_diff 数组差集
- SSM整合的一些配置(基于Maven工程,逆向工程,Restful风格)
- leetcode解题方案--024--Swap Nodes in Pairs
- Struts2_012_Struts中文处理
- PageHelper5.0.0分页插件与mybatis的集成
- spring httpMessageConverter 和 @ResponseBody
- 页面布局 --- 两列均分布局
- 基于Bmob,环信easeUI的校园二手交易市场——用户管理(含头像),数据管理,文件管理(图片管理),聊天功能的开发
- 看你的linux编译系统是32位还是64位最简单的方法以及不同数据类型占用字节个数
- 一些基础的数论知识
- 【Linux C 多线程编程】互斥锁与条件变量
- 八小时实现迷你版vuejs之二:vuejs 架构
- 倒排索引