首页 新闻 搜索 专区 学院

谁见过下面的异常?(ps:百度上有说是返回类型错了,也有说是传递参数的个数不对,可是我看都不是啊,报错说应该返回一条结果或是空的,结果却有15条记录,那该怎么处理呢)

0
悬赏园豆:5 [已关闭问题] 关闭于 2017-07-26 12:38
复制代码
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 15
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:364)
    at com.sun.proxy.$Proxy12.selectOne(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159)
    at com.xhw.dao.DaoSupport.findForObject(DaoSupport.java:110)
    at com.xhw.service.data.kwords.impl.KwordsService.findById(KwordsService.java:70)
    at com.xhw.service.data.kwords.impl.KwordsService$$FastClassBySpringCGLIB$$e67f5b02.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
    at com.xhw.service.data.kwords.impl.KwordsService$$EnhancerBySpringCGLIB$$2ae2a9ed.findById(<generated>)
    at com.xhw.controller.data.kwords.KwordsController.validateKwords(KwordsController.java:257)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
    at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
    at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 15
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
    at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:354)
    ... 76 more

复制代码
接口中代码
 public Boolean hasThisKwordId(String KwordId)throws Exception;
 public String findLastKwordId(String parentid)throws Exception;
Controller中代码
@RequestMapping(value="/validate")
    @ResponseBody
    public Object validateKwords() throws Exception {
        PageData pd = new PageData();       
        Map<String,Object> map = new HashMap<String,Object>();
        pd = this.getPageData();
        if (kwordsService.findById(pd)!=null) {
            map.put("msg", "true");
        }else{
            map.put("msg", "false");
        }
        return AppUtil.returnObject(pd, map);
    }
    @RequestMapping(value="/findkwordid")
    @ResponseBody
    public Object findKwordId() throws Exception{
        PageData pd = new PageData();       
        Map<String,Object> map = new HashMap<String,Object>();
        pd = this.getPageData();
        String nextKwordid=getNextKwordId(pd.getString("parentid"));
        map.put("nextKwordid", nextKwordid);
        return AppUtil.returnObject(pd, map);
    }
        private String getNextKwordId(String parentid) throws Exception {
        String lastKwordId=kwordsService.findLastKwordId(parentid);
        String nextKwordId="";
        if (StringUtil.isNullOrEmpty(lastKwordId)) {
            nextKwordId=CodeConst.KWORDS_KWORDID_ROOT.equals(parentid)
                          ?CodeConst.KWORDS_KWORDID_START
                          :parentid+CodeConst.KWORDS_KWORDID_START;
        }else {
            if (lastKwordId.length()>CodeConst.KWORDS_KWORDID_INTERVAL) {
                nextKwordId=parentid+StringUtil.haoAddOne(lastKwordId.substring(lastKwordId.length()-CodeConst.KWORDS_KWORDID_INTERVAL,lastKwordId.length()),CodeConst.KWORDS_KWORDID_FORMAT);
            }else {
                nextKwordId=StringUtil.haoAddOne(lastKwordId, CodeConst.KWORDS_KWORDID_FORMAT);
            }
        }
        return nextKwordId;
    }
Mapper中代码
    <select id="hasThisKwordId" parameterType="String" resultType="int">
        select 
        count(0)
        from 
        <include refid="tableName"></include>
        where 
            KWORDID = #{KWORDID}
    </select>
    <select id="findLastKwordId" parameterType="String" resultType="String">
        select 
        KWORDID
        from 
        <include refid="tableName"></include>
        where PARENTID=#{PARENTID}
        order by KWORDID desc
        limit 0,1
    </select>
jsp中代码
    function validateKwordId(str){
            var parentid=$("#PARENTID").val()
            var result=false
            $.ajax({
                url:'kwords/validate',
                data:{PARENTID:parentid,KWORDID:str},
                async:false,
                dataType:'json',
                type:'post',
                success:function(resp){
                    if(resp.msg=='true'){
                        result=true
                    }
                }
            });
            return result;
        }
        function validateKwordName(str){
            var parentid=$("#PARENTID").val()
            var result=false
            $.ajax({
                url:'kwords/validate',
                data:{PARENTID:parentid,KWORDNAME:str},
                async:false,
                dataType:'json',
                type:'post',
                success:function(resp){
                    if(resp.msg=='true'){
                        result=true
                    }
                }
            });
            return result;
        }

        function changeParentid(){
            var pid=$("#PARENTID").val()
            $.ajax( {  
                 type : "POST",  
                 url : "kwords/findkwordid",  
                 data : "parentid=" + pid,  
                 success : function(data) {  
                    $("#KWORDID").val(data.nextKwordId);  
                    if(validateKwordName($("#KWORDNAME").val())){
                        $("#KWORDNAME").tips({
                            side:3,
                            msg:'主题名称重复,请更换',
                            bg:'#AE81FF',
                            time:2
                        });
                        $("#KWORDNAME").focus();
                    }
                 },
                 error : function() {  
                    $("#KWORDID").tips({
                        side:3,
                        msg:'主题代码变更失败',
                        bg:'#AE81FF',
                        time:2
                    });
                    $("#KWORDID").focus();  
                 }  
                });  
        }

 

起风了~~~的主页 起风了~~~ | 小虾三级 | 园豆:505
提问于:2017-07-04 15:42
< >
分享
所有回答(2)
0

接口写的是什么?返回类型应该是集合,但是你写的是对象

~旗木卡卡东~ | 园豆:317 (菜鸟二级) | 2017-07-05 08:54
public Boolean hasThisKwordId(String KwordId)throws Exception;
public String findLastKwordId(String parentid)throws Exception;

可是,不管什么返回类型都是集合吗?

支持(0) 反对(0) 起风了~~~ | 园豆:505 (小虾三级) | 2017-07-05 13:24
0

 这个错误是你定义的方法只能返回一个entity,即一条数据,而你返回了一个list,即多条数据。若想返回多条定义的时候应该用List。 String只能返回一个字符串而不是list,或许你可以用行转列把多条转为一条,才会返回String

无殇-x | 园豆:4 (初学一级) | 2017-07-05 13:45

怎么转?

支持(0) 反对(0) 起风了~~~ | 园豆:505 (小虾三级) | 2017-07-05 13:53

@JAVA~~~:这个就是 ,()里填写你所查的字段, select  wm_concat(t.dummy) from dual t;

查出来的就是一行。这是最简单的用wm_concat 函数,不过这个函数最多能存4000,超过四千会报错。太长的话得自己写个函数吧。

支持(0) 反对(0) 无殇-x | 园豆:4 (初学一级) | 2017-07-05 14:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册