标签:
p=2#comments
<plugins> <!-- com.github.pagehelper为PageHelper类所在包名 --> <plugin interceptor="com.github.pagehelper.PageHelper"> <property name="dialect" value="mysql"/> <!-- 该參数默觉得false --> <!-- 设置为true时,会将RowBounds第一个參数offset当成pageNum页码使用 --> <!-- 和startPage中的pageNum效果一样--> <property name="offsetAsPageNum" value="true"/> <!-- 该參数默觉得false --> <!-- 设置为true时,使用RowBounds分页会进行count查询 --> <property name="rowBoundsWithCount" value="true"/> </plugin></plugins>
这几段插件配置的代码。应该放到Mybatis的config配置文件里,而非Maven。
后来。听Leader说,他在这也被误导了。搞了一天时间吧。
2. http://www.oschina.net/p/mybatis_pagehelperpublic void testPageHelperByStartPage() throws Exception { String logip = ""; String username = "super"; String loginDate = ""; String exitDate = null; String logerr = null; //不进行count查询。第三个參数设为false PageHelper.startPage(1, 10, false); //返回结果是Page<SysLoginLog> //该对象除了包括返回结果外。还包括了分页信息,能够直接按List使用 List<SysLoginLog> logs = sysLoginLogMapper .findSysLoginLog(logip, username, loginDate, exitDate, logerr); Assert.assertEquals(10, logs.size()); //当第三个參数没有或者为true的时候,进行count查询 PageHelper.startPage(2, 10); //返回结果是Page<SysLoginLog> //该对象除了包括返回结果外,还包括了分页信息,能够直接按List使用 Page<SysLoginLog> page = (Page<SysLoginLog>) sysLoginLogMapper .findSysLoginLog(logip, username, loginDate, exitDate, logerr); Assert.assertEquals(10, page.getResult().size()); //进行count查询。返回结果total>0 Assert.assertTrue(page.getTotal() > 0);PageHelper.startPage(1, 10);List<Country> list = countryMapper.selectAll();PageInfo page = new PageInfo(list);assertEquals(10, list.size());assertEquals(239, page.getTotal());
3.我的实际代码和效果
Mybatis分页插件PageHelper正确的用法(网上有2篇不够科学的文章)
标签:
原文地址:http://www.cnblogs.com/yxwkf/p/5250828.html