v3.2.2简单重构优化代码。 新增PageInfo包装类,对分页结果Page进行封装,方便EL使用。 将SystemMetaObject类的fromObject方法内置到分页插件中,方便低版本的Mybatis使用该插件。
v3.2.1新增offsetAsPageNum参数,用来控制RowBounds中的offset是否作为pageNum使用,pageNum和startPage中的含义相同,pageNum是页码。该参数默认为false,使用默认值时,不需要配置该参数。 新增rowBoundsWithCount参数,用来控制使用RowBounds时是否执行count查询。该参数默认为false,使用默认值时,不需要配置该参数。
使用方法 将本插件中的两个类Page.java和PageHelper.java放到项目中,如果需要使用PageInfo.java,也可以放到项目中。
或者如果你使用Maven,你可以添加如下依赖:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
< plugins >
< plugin interceptor = "com.github.pagehelper.PageHelper" >
< property name = "dialect" value = "mysql" />
< property name = "offsetAsPageNum" value = "true" />
< property name = "rowBoundsWithCount" value = "true" />
</ plugin >
</ plugins >
|
这里的com.github.pagehelper.PageHelper使用完整的类路径。
其他三个参数说明: 增加dialect属性,使用时必须指定该属性,可选值为oracle,mysql,hsqldb,没有默认值,必须指定该属性。 增加offsetAsPageNum属性,默认值为false,使用默认值时不需要增加该配置,需要设为true时,需要配置该参数。当该参数设置为true时,使用RowBounds分页时,会将offset参数当成pageNum使用,可以用页码和页面大小两个参数进行分页。 增加rowBoundsWithCount属性,默认值为false,使用默认值时不需要增加该配置,需要设为true时,需要配置该参数。当该参数设置为true时,使用RowBounds分页会进行count查询。
简单示例: 1 2 3 4 5 | PageHelper.startPage( 1 , 10 );
List<Country> list = countryMapper.selectAll();
PageInfo page = new PageInfo(list);
assertEquals( 10 , list.size());
assertEquals( 239 , page.getTotal());
|
更多示例请查看Mybatis-Sample项目:
http://git.oschina.net/free/Mybatis-Sample |