赞
踩
一、前言
关于使用mybatis报"org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3"错误异常,详情日志如下org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3@b@at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76) ~[mybatis-spring-1.2.3-1.2.3.jar:1.2.3]@b@at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) ~[mybatis-spring-1.2.3-1.2.3.jar:1.2.3]@b@at com.sun.proxy.$Proxy37.selectOne(Unknown Source) ~[?:?]@b@at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:165) ~[mybatis-spring-1.2.3-1.2.3.jar:1.2.3]@b@at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:69) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@at com.sun.proxy.$Proxy58.getPageCount(Unknown Source) ~[?:?]@b@at com.xwood.portal.info.service.impl.NewInfoServiceImpl.getPageTotal(NewInfoServiceImpl.java:56) ~[bin/:?]@b@at com.xwood.portal.info.service.impl.NewInfoServiceImpl.getPageTotal(NewInfoServiceImpl.java:1) ~[bin/:?]@b@at com.xwood.portal.info.web.controller.NewInfoInfoController.searchEntry(NewInfoInfoController.java:57) [bin/:?]@b@at com.xwood.portal.info.web.controller.NewInfoInfoController
二、解决方法
1.原因分析 - mybatis配置文件getPageCount因group by返回多条记录,对于NewInfoDAO.java的方法返回是java.lang.Integer整型类型<?xml version="1.0" encoding="UTF-8" ?> @b@mapper @b@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @b@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">@b@ @b@@b@@b@@b@SELECT COUNT(1) FROM PMS_NEWINFO_INFO @b@ DATA_STATUS ='1' @b@ @b@@b@and CREATED_DATE >= to_char(to_date(#{startCreateDate},'yyyy-mm-dd'),'yyyymmdd')@b@@b@@b@and CREATED_DATE <= to_char(to_date(#{endCreateDate}, 'yyyy-mm-dd'),'yyyymmdd')@b@@b@@b@group by FOLDER_NAME,WEB_SITE_ID@b@@b@ @b@public interface NewInfoDAO extends BaseMapper {@b@@b@ @b@/**@b@ * 获取分页总记录数@b@ * @param parameterObj 条件入参@b@ * @throws Exception@b@ * @return@b@ */@b@public Integer getPageCount(Map,?> parameterObj) throws Exception;@b@@b@ @b@}
2. 解决方法 - 删除group by FOLDER_NAME,WEB_SITE_ID,这样对应返回NewInfoDAO的getPageCount方法的整型数据<?xml version="1.0" encoding="UTF-8" ?> @b@mapper @b@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @b@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">@b@ @b@@b@@b@@b@SELECT COUNT(1) FROM PMS_NEWINFO_INFO @b@ DATA_STATUS ='1' @b@ @b@@b@and CREATED_DATE >= to_char(to_date(#{startCreateDate},'yyyy-mm-dd'),'yyyymmdd')@b@@b@@b@and CREATED_DATE <= to_char(to_date(#{endCreateDate}, 'yyyy-mm-dd'),'yyyymmdd')@b@@b@ @b@ @b@@b@
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。