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 !&quot;&quot;.equals(customerId.trim())">
and customer_id like concat('%',trim(#{customerId}),'%')
</if>
<if test="remark != null and !&quot;&quot;.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 !&quot;&quot;.equals(groupBy.trim())">
group by ${groupBy}
</if>
</select>
public interface ContactRecordMapper {

    PageList<ContactRecord> selectPageList(Map<String, Object> whereMap,
PageBounds pb); }

springMVC集成mybatis-paginator实现分页的更多相关文章

  1. SpringBoot集成Mybatis并具有分页功能PageHelper

    SpringBoot集成Mybatis并具有分页功能PageHelper   环境:IDEA编译工具   第一步:生成测试的数据库表和数据   SET FOREIGN_KEY_CHECKS=0;   ...

  2. springboot如何集成mybatis的pagehelper分页插件

    mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...

  3. spring boot 集成mybatis plus 含分页 完整教程

    一.添加依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus ...

  4. SpringMVC集成Mybatis

    1.pom.xml中添加引入架包 <dependency> <groupId>mysql</groupId> <artifactId>mysql-con ...

  5. springmvc+mybatis集成配置

    简单之美,springmvc,mybatis就是一个很好的简单集成方案,能够满足一般的项目需求.闲暇时间把项目配置文件共享出来,供大家参看: 1.首先我们来看下依赖的pom: <!-- spri ...

  6. spring+websocket综合(springMVC+spring+MyBatis这是SSM框架和websocket集成技术)

    java-websocket该建筑是easy.儿童无用的框架可以在这里下载主线和个人教学好java-websocket计划: Apach Tomcat 8.0.3+MyEclipse+maven+JD ...

  7. SpringBoot集成MyBatis的分页插件 PageHelper

    首先说说MyBatis框架的PageHelper插件吧,它是一个非常好用的分页插件,通常我们的项目中如果集成了MyBatis的话,几乎都会用到它,因为分页的业务逻辑说复杂也不复杂,但是有插件我们何乐而 ...

  8. 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法

    spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...

  9. 集成SpringMVC, Spring, Mybatis环境

    web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version=" ...

随机推荐

  1. IO流--FileReader&&FileWriter

    (一)FileReader (1)第一种读取方式 package com.songyan.fileReader; import java.io.FileNotFoundException; impor ...

  2. spark 持久化机制

    spark的持久化机制做的相对隐晦一些,没有一个显示的调用入口. 首先通过rdd.persist(newLevel: StorageLevel)对此rdd的StorageLevel进行赋值,同chec ...

  3. node.js学习一——什么是node.js

    定义:node.js是运行在服务器端的运用了谷歌v8引擎的javascript运行平台 特点:1. 异步式I/O(非阻塞式I/O) 2. 事件驱动 什么是异步式I/O(非阻塞式I/O)? 要了解什么是 ...

  4. Metesploit使用随笔

    平时在工作中真正用到metesploit机会不多,偶尔也会用来做漏洞验证,但是每次使用的时候都需要花点时间回忆一下具体是怎么用的,因此索性记下来方便自己,以使用Nessus扫描YS的某个硬件设备发现的 ...

  5. ZooKeeper本身是一个分布式应用程序,为写入分布式应用程序提供服务。

    ZooKeeper本身是一个分布式应用程序,为写入分布式应用程序提供服务. 作为ZooKeeper架构的一部分的每个组件在下表中进行了说明. 部分 描述 Client(客户端) 客户端,我们的分布式应 ...

  6. 各种分布 高斯 Gamma Beta 多项分布

  7. Admin Finder

    #Created for coded32 and his teamopenfire Eliminated Some bugs from my last code shared here as Gues ...

  8. 利用saltstack的event实现自己的功能

    saltstack的master上minion连接较多,下面这个程序可以分析哪些minion任务执行成功,哪些执行失败以及哪些没有返回. 脚本说明: 一.最先打印出本次任务的job id.comman ...

  9. struts2设置文件上传大小

    利用struts2想要设置或者限制上传文件的大小,可以在struts.xml配置文件里面进行如下配置: <constant name="struts.multipart.maxSize ...

  10. Netty源码细节-accept、read(Linux os层 + Netty层代码细节)(转)

    原文:http://budairenqin.iteye.com/blog/2215899 这篇分析一下accept的细节, 我觉得网络IO相关开发很多时候不能仅仅局限于java层, 尤其从accept ...