org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map

同事让我帮他找一个错误,他说明明写的对的,怎么老是报错。其实,使用MyBaties在编写sql配置文件时,都会遇到的一个小问题,问题虽小,对初学者可能都会碰到。

org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map com.boco.fsmsys.amuse.dao.AmuseItemDao.amuseItem

at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementParameterMap(MapperBuilderAssistant.java:326)

at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:290)

at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:110)

at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:567)

at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:493)

at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:488)

at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:236)

at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:71)

at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:39)

at $Proxy9.find(Unknown Source)

at com.boco.fsmsys.amuse.service.impl.AmuseItemServiceImpl.find(AmuseItemServiceImpl.java:31)

at com.boco.fsmsys.amuse.service.impl.AmuseItemServiceImpl$$FastClassByCGLIB$$f42525b0.invoke(<generated>)

at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)

at com.boco.fsmsys.amuse.service.impl.AmuseItemServiceImpl$$EnhancerByCGLIB$$b6a4972c.find(<generated>)

at com.boco.fsmsys.test.service.AmuseItemServiceTest.testFind(AmuseItemServiceTest.java:15)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)

at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

at org.junit.runners.ParentRunner.run(ParentRunner.java:220)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.lang.IllegalArgumentException: Parameter Maps collection does not contain value for com.boco.fsmsys.amuse.dao.AmuseItemDao.amuseItem

at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:660)

at org.apache.ibatis.session.Configuration.getParameterMap(Configuration.java:442)

at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementParameterMap(MapperBuilderAssistant.java:324)

... 45 more


    从异常的提示发现是配置文件中,find这个方法的sql参数类型或者名称写错了,但是你发现这个位置并没有些写错。于是你很困惑,其实问题就在这个配置文件中,提示的也对,只是位置不对。mybaties中只要有任何一个地方报错,都无法通过。最后发现是另个一个方法上将parameterType写成了parameterMap了(

  1. <select id="getClassByID" parameterMap="String" resultMap="classResultMap">  

)。

再者之所以大家犯错,有一个原因是在编写配置文件时,会提示parameterMap ,但是这个在mybaties中已经不再用这个属性了。所以大家写配置文件时,要小心细心。

你可能感兴趣的:(mybaties)