1.场景描述:后台管理系统
2.需求:对查询结果分页展示
3.使用框架:mybatis ,Spring,Springmvc
问题描述:
在以tomcat启动项目时卡在
2013-11-10 10:36:43,963 [pool-2-thread-1] INFO com.mchange.v2.log.MLog - MLog clients using log4j logging.
2013-11-10 10:36:44,041 [pool-2-thread-1] INFO com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
待tomcat启动过期时间到时会提示java heap space 内存溢出。
解决方案1
按照网上提示更改tomcat–>jdk–>VM arguments 设置-Xmx1024M -Xms512M -XX:MaxPermSize=256m根据实际需求做更改。可参考此文章:http://wangqiaowqo.iteye.com/blog/457912/
解决方案2
如果上述方式解决了你的问题确实很好,但如果你犯了跟我一样的错误,那么上述方式可能解决不了你的问题。因为公司用的都是jdk1.6,我用的myeclipse 10 自带jdk1.6也就没有换掉。我这里的问题是设置上述参数后并没有奏效所以接下来索性换成了自己按照的jdk1.7,结果是OK。可以正常启动了。
解决方案3
如果你和我一样粗心的话,那么你的问题依然没有解决,执行xxxMapper.selectByExample(example);时会出现 Java.Lang.NoSuchMethod …reflection ..的错误。一开始怀疑自己配置有问题,检查了一下,确认无误,然后把把PageHelper.startPage(pageNum,numPage);去掉测试了一下,结果是可以查询。=================分界线==================
废话不多说了,是因为jar包不匹配,这里我公布一下我的jar配比。
mybatis-3.2.8.jar
mybatis-spring-1.2.2
mybatis-paginator-1.2.15
pagehelper-3.4.2-fix.jar
如需要可通过以下方式获取:
链接: http://pan.baidu.com/s/1jHcSJQY 密码: w2ny
解决方案4
查看你的XXmapper.xml文件有没有配置错误。
可参考:http://blog.csdn.net/rj042/article/details/15026795
最后附上本人的代码和配置:
代码:
public PageInfoUtil getPageInfo(As2oss as2oss, Integer pageNum,
Integer numPerPage) {
PageInfoUtil pageInfo = new PageInfoUtil();
if (pageNum == null) {
pageNum = 1;
}
if (numPerPage == null) {
numPerPage = 20;
}
// 分页处理
PageHelper.startPage(pageNum, numPerPage);
// 执行查询
As2ossExample example = new As2ossExample();
List<As2oss> list = as2ossMapper.selectByExample(example);
// 取分页信息
PageInfo<As2oss> pageInfo1 = new PageInfo<As2oss>(list);
// 返回处理结果
pageInfo.setTotal(pageInfo1.getTotal());
pageInfo.setList(list);
pageInfo.setPageNum(pageInfo1.getPageNum());
pageInfo.setPageSize(pageInfo1.getPageSize());
return pageInfo;
}
PageInfo中会包装其他需要参数,本人依照业务需求做了自己的包装。所以,方法不是唯一的,能达到目的就好。
配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- changes from the defaults for testing -->
<setting name="cacheEnabled" value="true" />
<setting name="useGeneratedKeys" value="true" />
<setting name="defaultExecutorType" value="REUSE" />
</settings>
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql" />
</plugin>
</plugins>
</configuration>