• MyBatis的mapper.xml文件的参数问题:org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map


    配置参数类型有两种选择,即:parameterType和parameterMap

    不管参数是否是基本数据类型还是map类型,都是使用parameterType。

    版权声明:本文为博主原创文章,未经博主允许不得转载。

    原文地址:

    https://www.cnblogs.com/poterliu/p/9282527.html

    parameterMap和resultMap类似,parameterMap通常应用于mapper中有多个参数要传进来时,表示将查询结果集中列值的类型一一映射到java对象属性的类型上,在开发过程中不推荐这种方式。

    如果不小心将parameterType写成了parameterMap,如下:

    Mapper.java文件

    public Long deletePayer(Map<String, Object> paraMap);

    Mapper.xml文件

    <delete id="deletePayer" parameterMap="map" >
        delete from payer_info where id=#{id}
    </delete>

    如果Mapper.xml文件没有配置对应parameterMap,这样就会报找不到对应的parameterMap:

    org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map com.xxx.yyy.portal.dao.IPayerInfoDao.map
        at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementParameterMap(MapperBuilderAssistant.java:346)
        at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:310)
        at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109)
        at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:698)
        at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:668)
        at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:663)
        at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:175)
        at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:38)
        at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42)
        at com.sun.proxy.$Proxy25.getUserInfoByAccount(Unknown Source)
        at com.xxx.yyy.portal.service.impl.UserInfoServiceImpl.getUserInfoByAccount(UserInfoServiceImpl.java:30)
        at com.xxx.yyy.portal.controller.UserInfoController.ajaxLogin(UserInfoController.java:59)
        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:781)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        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:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
        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:724)
    Caused by: java.lang.IllegalArgumentException: Parameter Maps collection does not contain value for com.xxx.yyy.portal.dao.IPayerInfoDao.map
        at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:791)
        at org.apache.ibatis.session.Configuration.getParameterMap(Configuration.java:570)
        at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementParameterMap(MapperBuilderAssistant.java:344)
        ... 54 more

    mapper.xml文件正确的写法:

    <delete id="deletePayer" parameterType="map" >
        delete from payer_info where id=#{id}
    </delete>

    在开发过程中,一定要注意你选择的是parameterType还是parameterMap,如果你发现你选择的是parameterMap,这时你就要小心了,很可能这时项目中一个隐藏的bug,而且还不容易发现,因为报错的信息很模糊,不容易定位到这个问题上来。

  • 相关阅读:
    JVM01---简介
    SpringBoot-01创建项目,实例
    git的三种提交方式(目前两种)
    Spring-事务
    JDK及CGLIB动态代理-AOP4种增强
    Spring-静态代理
    Spring-Aop
    初识jvm-1.Java类的加载机制
    java公开课-06-实用类
    java公开课-05-集合及Socket网络编程(简介)
  • 原文地址:https://www.cnblogs.com/poterliu/p/9282527.html
Copyright © 2020-2023  润新知