mybatis-paginator下载地址:https://github.com/miemiedev/mybatis-paginator
1、引入maven依赖
com.github.miemiedev mybatis-paginator 1.2.17
2、spring配置文件添加分页插件:
class="org.mybatis.spring.SqlSessionFactoryBean">
class="org.mybatis.spring.mapper.MapperScannerConfigurer">
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 whereMap = new HashMap();whereMap.put( "customerId", customerId);whereMap.put( "remark", remark); PageBounds pb = new PageBounds(curPage, pageSize, Order.formString("id.desc" )); PageList 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 queryPageContactRecord (Map whereMap, PageBounds pb) { return recordMappert.selectPageList(whereMap, pb);}
3.3、dao层接口方法及其xmp配置
<if test&#61;"customerId !&#61; null and !"".equals(customerId.trim())">and customer_id like concat( &#39;%&#39;,trim(#{customerId}),&#39;%&#39;) if ><if test&#61;"remark !&#61; null and !"".equals(remark.trim())">and REMARK like concat( &#39;%&#39;,trim(#{remark}),&#39;%&#39;) if > selectPageList " parameterType&#61;"map" resultMap&#61;"BaseResultMap">select * from contact_record <if test&#61;"groupBy !&#61; null and !"".equals(groupBy.trim())">group by ${groupBy} if >
public interface ContactRecordMapper {PageList selectPageList (Map whereMap,PageBounds pb);}