springMVC集成mybatis-paginator实现分页
mybatis-paginator下载地址:https://github.com/miemiedev/mybatis-paginator
1、引入maven依赖
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>1.2.17</version>
</dependency>
2、spring配置文件添加分页插件:
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-setting.xml"/>
<property name="mapperLocations" value="classpath*:com/tianwen/nlp/mapping/*.xml"></property>
<property name="plugins">
<list>
<bean class="com.github.miemiedev.mybatis.paginator.OffsetLimitInterceptor">
<property name="dialectClass" value="com.github.miemiedev.mybatis.paginator.dialect.MySQLDialect"/>
</bean>
</list>
</property>
</bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.tianwen.nlp.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
3、下面添加一分页插件调用事例
3.1、controller层方法
//分页查询回访记录列表
@RequestMapping("/contactList")
public String contactList(Model model,
@RequestParam(value="customerId", required=false)String customerId,
@RequestParam(value="remark", required=false)String remark,
@RequestParam(value="page", defaultValue="1")Integer curPage,
@RequestParam(value="pageSize", defaultValue="20")Integer pageSize) {
Map<String, Object> whereMap = new HashMap<String, Object>();
whereMap.put("customerId", customerId);
whereMap.put("remark", remark);
PageBounds pb = new PageBounds(curPage, pageSize, Order.formString("id.desc"));
PageList<ContactRecord> pageList= contactService.queryPageContactRecord(whereMap, pb);
Page page = new Page(curPage, pageList.getPaginator().getTotalCount(), pageSize); //根据当前页码、总记录数、每页记录数构造page对象
model.addAttribute("data", pageList);
model.addAttribute("page", page);
return "contact/contactList";
}
3.2、service层方法
@Override
public PageList<ContactRecord> queryPageContactRecord(
Map<String, Object> whereMap, PageBounds pb) {
return recordMappert.selectPageList(whereMap, pb);
}
3.3、dao层接口方法及其xmp配置
<sql id="whereCondition">
<if test="customerId != null and !"".equals(customerId.trim())">
and customer_id like concat('%',trim(#{customerId}),'%')
</if>
<if test="remark != null and !"".equals(remark.trim())">
and REMARK like concat('%',trim(#{remark}),'%')
</if>
</sql> <!-- 分页查询回访记录 -->
<select id="selectPageList" parameterType="map" resultMap="BaseResultMap">
select * from contact_record
<where>
<include refid="whereCondition"></include>
</where>
<if test="groupBy != null and !"".equals(groupBy.trim())">
group by ${groupBy}
</if>
</select>
public interface ContactRecordMapper {
PageList<ContactRecord> selectPageList(Map<String, Object> whereMap,
PageBounds pb);
}
springMVC集成mybatis-paginator实现分页的更多相关文章
- SpringBoot集成Mybatis并具有分页功能PageHelper
SpringBoot集成Mybatis并具有分页功能PageHelper 环境:IDEA编译工具 第一步:生成测试的数据库表和数据 SET FOREIGN_KEY_CHECKS=0; ...
- springboot如何集成mybatis的pagehelper分页插件
mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...
- spring boot 集成mybatis plus 含分页 完整教程
一.添加依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus ...
- SpringMVC集成Mybatis
1.pom.xml中添加引入架包 <dependency> <groupId>mysql</groupId> <artifactId>mysql-con ...
- springmvc+mybatis集成配置
简单之美,springmvc,mybatis就是一个很好的简单集成方案,能够满足一般的项目需求.闲暇时间把项目配置文件共享出来,供大家参看: 1.首先我们来看下依赖的pom: <!-- spri ...
- spring+websocket综合(springMVC+spring+MyBatis这是SSM框架和websocket集成技术)
java-websocket该建筑是easy.儿童无用的框架可以在这里下载主线和个人教学好java-websocket计划: Apach Tomcat 8.0.3+MyEclipse+maven+JD ...
- SpringBoot集成MyBatis的分页插件 PageHelper
首先说说MyBatis框架的PageHelper插件吧,它是一个非常好用的分页插件,通常我们的项目中如果集成了MyBatis的话,几乎都会用到它,因为分页的业务逻辑说复杂也不复杂,但是有插件我们何乐而 ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
- 集成SpringMVC, Spring, Mybatis环境
web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version=" ...
随机推荐
- JavaScript异步编程的Promise模式(转)
异步模式在web编程中变得越来越重要,对于web主流语言Javascript来说,这种模式实现起来不是很利索,为此,许多Javascript库(比如 jQuery和Dojo)添加了一种称为promis ...
- Spring学习——DI(依赖注入)
IOC容器,处理对象依赖关系 IOC与DI: IOC :是一个容器,创建对象的容器 DI :在容器创建对象后,处理对象的依赖关系,也叫依赖注入! 方式1:通过set方法注入值 可以给普通属性.集合属性 ...
- React Native 让组件做到局部刷新
利用RN的状态机机制,我们可以通过this.setState({optional:...})来控制界面的刷新,但是一定会触发render方法,那如何保证不调用render方法从而做到界面的局部刷新呢? ...
- iOS开发之指定UIView的某几个角为圆角
我们知道, 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某几个角(小于4)为圆角 ...
- javolution-core-java-6.1.0.jar 的使用
官方网址:http://javolution.org/apidocs/javolution/io/Struct.html 第一步:导包 第二步:创建继承的结构体 结构体定义如下所示: public c ...
- JavaScript中的模块化之AMD和CMD
前言: 为什么我们需要模块化开发,模块化开发的好处有哪些? 首先我们先说一下非模块化的开发方式带来的弊端. 非模块化开发中会导致一些问题的出现,变量和函数命名可能相同,会造成变量污染和冲突,并且出错时 ...
- CSS3: box-shadow 阴影
box-shadow是给元素块添加周边阴影效果 语法: 对象选择器 {box-shadow:X轴偏移量 Y轴偏移量阴影 模糊半径 阴影扩展半径 阴影颜色 [投影方式] } box-shadow: h- ...
- mysql 初始化报错 /usr/local/mysql/bin/mysqld:error while loading shared libraries :libaio.so.1
安装mysql在初始化的时候,出现/usr/local/mysql/bin/mysqld:error while loading shared libraries:libaio.so.1 :canno ...
- 【Sofa】Sofa比赛成绩记录
最高得到过第4名,然后后面跌倒了第7名,现在追到了第6名.虽然名次还不是最高,但是很开心,今天能在一道一直困扰的题目上有突破,就是那个自行车预测的题目,开始过拟合了.后面进行了一些处理,效果很明显.继 ...
- IE漏洞调试之CVE-2013-3893
前言 Windows平台的漏洞挖掘和安全研究中,IE始终是绕不开的话题.IE漏洞就跟adobe系列一样经典,是学习exploit.shellcode的绝佳途径. 在IE漏洞中,UAF即Use-Afte ...