mybatis-paginator是gethub上的一个开源项目、用于java后台获取分页数据、该开源项目还提供一个列表组件(mmgrid)用于前端展示。
2、该开源项目的使用说明:
Maven中加入依赖
...
com.github.miemiedev
mybatis-paginator
1.2.10
...
3、Mybatis配置文件添加分页插件:
4、Mybatis中创建一个查询,内容可以是任何Mybatis表达式
SPXX01, SPXX02, GYS01, GYS02
5、Dao层代码
package com.pcmall.dao.sale.xqt;
import java.util.List;
import java.util.Map;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.pcmall.domain.sale.xqt.XqtSpxx;
public interface XqtSpxxMapper {
List selectXqtSpxx(Map map, PageBounds page);
}
6、Service层代码
接口:
package com.pcmall.service.sale.xqt;
import java.util.List;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.pcmall.domain.sale.xqt.XqtSpxx;
import com.pcmall.domain.vo.ResponseVO;
public interface IXqtSpxxService {
List queryXqtSpxx(String spxx01, String spxx02, String gys01,
String gys02, PageBounds page);
}
实现类:
package com.pcmall.service.sale.xqt.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.pcmall.dao.sale.xqt.XqtSpxxMapper;
import com.pcmall.domain.sale.xqt.XqtSpxx;
import com.pcmall.domain.vo.ResponseVO;
import com.pcmall.service.sale.xqt.IXqtSpxxService;
@Service
public class XqtSpxxService implements IXqtSpxxService {
@Resource
private XqtSpxxMapper xqtSpxxMapper;
@Override
public List queryXqtSpxx(String spxx01, String spxx02,
String gys01, String gys02, PageBounds page) {
List xqtSpxxList = new ArrayList();
Map map=new HashMap();
map.put("spxx01", spxx01);
map.put("spxx02", spxx02);
map.put("gys01", gys01);
map.put("gys02", gys02);
xqtSpxxList = xqtSpxxMapper.selectXqtSpxx(map, page);
return xqtSpxxList;
}
}
7、Controller层代码
@RequestMapping("/selXqtSpxx")
@ResponseBody
public List selXqtSpxx(
@RequestParam(required = false, defaultValue = "1") int startIndex,
@RequestParam(required = false, defaultValue = "10") int pageSize,
HttpServletRequest request) throws UnsupportedEncodingException {
List xqtSpxxList = new ArrayList();
request.setCharacterEncoding("ISO-8859-1");
String spxx01 = request.getParameter("spxx01");
String spxx02 = request.getParameter("spxx02")==null?null:new String(request.getParameter("spxx02").getBytes("ISO8859_1"),"UTF-8");
String gys01 = request.getParameter("gys01");
String gys02 = request.getParameter("gys02")==null?null:new String(request.getParameter("gys02").getBytes("ISO8859_1"),"UTF-8");
xqtSpxxList = xqtSpxxServiceImpl.queryXqtSpxx(spxx01, spxx02,
gys01, gys02, new PageBounds(startIndex / pageSize + 1,
pageSize));
return xqtSpxxList;
}
8、前端jsp、js代码如下
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/core/global.jsp"%>
新奇特商品维护
商品编码
商品名称
供应商编码
供应商名称
操作