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=" ...
随机推荐
- 分布式缓存DistributedCache的使用
分布式缓存用于将使用的小文件首先分发到各个datanode节点上,然后利用map/reduce阶段的setup()方法将文件内容读入内存,加快程序执行.具体实现方法如下: http://demievi ...
- ntp流量放大攻击分析
最近,听说挂在网络上的设备进行时间同步成功率低,YS需要架设自己的NTP服务器,这玩意第一时间能让人想到NTP流量放大攻击,这也是一种比较古老的攻击方式,检测了一下发现所使用的OS默认已经进行了加固, ...
- 【C语言】 Linux下编译提示pow未定义引用
如下代码: #include <stdio.h> // 调用基本输入输出函数库 #include <math.h> #define PI 3.14 // 定义常量 float ...
- ZooKeeper服务器是用Java创建的,它在JVM上运行。
ZooKeeper服务器是用Java创建的,它在JVM上运行. 创建配置文件 使用命令 vi conf/zoo.cfg 和所有以下参数设置为起点,打开名为 conf/zoo.cfg 的配置文件. $ ...
- vue中的组件,Component元素,自定义路由,异步数据获取
组件是Vue最强大的功能之一.组件是一组可被复用的具有一定功能,独立的完整的代码片段,这个代码片段可以渲染一个完整视图结构组件开发如何注册组件?第一步,在页面HTML标签中使用这个组件名称,像使用DO ...
- 建立DB-LINK和建立视图
在系统数据通信间经常会有数据库的数据直接引用,使用视图VIEW的方式实现.视图调用通常会有两种情况,一种是同一数据库的视图,一种是跨数据库的视图. 在同一数据库地址不同用户下,不过不同的用户视图调用需 ...
- Oracle使用row_number()函数查询时增加序号列
使用Oracle自带的row_number()函数能够实现自动增加序号列的要求,但是同时引发一个问题,如果我们查询出来的数据需要使用Order By排序的话,那么我们会发现新增加的序号列是乱序的,它会 ...
- 【枚举】【SDOI 2011】【bzoj 2241】打地鼠
2241: [SDOI2011]打地鼠 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 877 Solved: 557 Description 打地鼠是 ...
- 集成方法:渐进梯度回归树GBRT(迭代决策树)
http://blog.csdn.net/pipisorry/article/details/60776803 单决策树C4.5由于功能太简单.而且非常easy出现过拟合的现象.于是引申出了很多变种决 ...
- 用聚合数据API(苏州实时公交API)快速写出小程序
利用聚合数据API快速写出小程序,过程简单. 1.申请小程序账号 2.进入开发 3.调用API.比如“苏州实时公交”小程序,选择的是苏州实时公交API. 苏州实时公交API文档:https://www ...