easyUI-SSM分页技术

分页(pageHelper插件)

后台实现步骤:
1、在parent工程中添加pagehelper管理包(版本5.12)
在mapper(dao层)工程中加pagehelper依赖包;
2、在web项目Mybatis的配置文件配置sqlMapConfig.xml文件(mybatis-config.xml)
内容:
<plugins><!--配置pagehelper插件-->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- 此处省略,有db的url自动识别 -->
<!-- <property name="dialect" value="mysql"></property> -->
</plugin>
</plugins>
3、 在spring-mybatis.xml中给sqlSessionFactory添加属性
<!-- 配置mybatis的分页插件 -->
<property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml">
</property>

4、在utils工程中写公共的pojo

package com.j17.common.pojo;

import java.util.List;
/**
*封装datagrid插件的响应数据格式
* @author Administrator
*
*/
public class DataGridResult {

private long total;//总记录数
private List<?> rows;//当前页的结果集
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public List<?> getRows() {
return rows;
}
public void setRows(List<?> rows) {
this.rows = rows;
}

@Override
public String toString() {
return "DataGridResult [total=" + total + ", rows=" + rows + "]";
}
}

5、实现service中的分页方法

@Override
public DataGridResult findItemByPage(Integer page, Integer pageSize) {
//默认example对象,以此为条件的查询是全表查
TbItemExample example = new TbItemExample();
//设置分页特征
//此句放置与原始查询前,会将院查询转为带分页特征的查询,交给执行单元继续执行
PageHelper.startPage(page, pageSize);
List<TbItem> items = itemMapper.selectByExample(example);//执行查询
DataGridResult result = new DataGridResult();
result.setRows(items);
//获取分页信息
PageInfo info= new PageInfo<>(items);
long total = info.getTotal();//得到总记录数
result.setTotal(total);
return result;
}
6、controller层

/**
*
* @param pageNum
* 当前页码
* @param pageSize
* 每页记录数
* @return
*/
@RequestMapping(value = "/items", method = RequestMethod.POST)
@ResponseBody
public DataGridResult showItemPages(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
@RequestParam(value = "rows", defaultValue = "10") Integer pageSize) {

DataGridResult result = itemService.findItemByPage(pageNum, pageSize);
return result;
}


原文地址:https://www.cnblogs.com/li2beyond/p/8315286.html