解决Parameter '__frch_item_0' not found. Available parameters are [list]

版权声明:本文为博主原创文章,允许转载不允许复制。 https://blog.csdn.net/qq_30938705/article/details/80117629

异常如下:

四月 28, 2018 10:07:49 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springMVC] in context with path [/onlinetest] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found. Available parameters are [list]] with root cause
org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found. Available parameters are [list]
	at org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap.get(DefaultSqlSession.java:261)
	at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:44)
	at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)
	at org.apache.ibatis.reflection.MetaObject.metaObjectForProperty(MetaObject.java:138)
	at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:109)
	at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:76)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61)
	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:47)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:141)
	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.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:408)
	at com.sun.proxy.$Proxy13.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:254)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy23.insertDescide(Unknown Source)
	at com.lkl.service.impl.AddTestServiceImpl.insertDescide(AddTestServiceImpl.java:66)
	at com.lkl.controller.AddTestController.addTest(AddTestController.java:99)
	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.doInvoke(InvocableHandlerMethod.java:221)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	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.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
	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.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
	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:505)
	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:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	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)

解决方法:

1.查看parameterType的类型是不是java.util.List类型,如果是的话,看foreach 的collection属性是不是list,因为 传递一个 List 实例或者数组作为参数对象传给 MyBatis,MyBatis 会自动将它包装在一个 Map 中,用名称在作为键。List 实例将会以“list” 作为键,而数组实例将会以“array”作为键
2.看foreach里面的名称字段是否写错,实体类的字段类型是否对应数据库的类型




阅读更多

Mybatis foreach 问题 Parameter 'item' not found. Available parameters are [list]

01-19

Mybatis 3.1.1rnMybatis-Spring 1.1.1rn都是目前最新的,其他版本的我也试过都有问题。rnrnsqlmap如下,删除语句没有问题,只有用到foreach的时候会出问题rnrn[code=html]rn rn rn select * from t_user where user_id in rn <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> rn #item rn </foreach> rn rn rn rn rn rn delete from t_user where user_id = #userIdrn rn [/code]rnrn测试代码如下:rn[code=java]@Testrn public void testQueryForListByUserId()rn rn List userIds = new ArrayList();rn userIds.add(1);rn userIds.add(2);rn rn List list = userDao.queryForListByUserId(userIds);rn rn //Assert.assertNotNull(list);rn rn for(User user : list)rn System.out.print(user.getUserId() + "\t" + user.getUserName() +":");rn rn System.out.println();rn rn rn [/code]rnrn问题如下:rn[code=text]02:26:10.490 [main] DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [com.mysql.jdbc.JDBC4Connection@169dd64] will not be managed by Springrn02:26:10.499 [main] DEBUG c.a.m.d.u.U.queryForListByUserId - ooo Using Connection [com.mysql.jdbc.JDBC4Connection@169dd64]rn02:26:10.503 [main] DEBUG c.a.m.d.u.U.queryForListByUserId - ==> Preparing: select * from t_user where user_id in ? rn02:26:10.533 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1406eb6]rnFAILED: testQueryForListByUserIdrnorg.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'item' not found. Available parameters are [list]rn at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)rn at $Proxy16.selectList(Unknown Source)rn at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:195)rn at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:124)rn at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:90)rn at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)rn at $Proxy17.queryForListByUserId(Unknown Source)rn at com.abrahu.mybatis.user.role.Test_UserDao.testQueryForListByUserId(Test_UserDao.java:45)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)rn at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:182)rn at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:194)rn at org.testng.internal.Invoker.invokeMethod(Invoker.java:695)rn at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894)rn at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219)rn at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)rn at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)rn at org.testng.TestRunner.privateRun(TestRunner.java:768)rn at org.testng.TestRunner.run(TestRunner.java:617)rn at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)rn at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)rn at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)rn at org.testng.SuiteRunner.run(SuiteRunner.java:240)rn at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)rn at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)rn at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)rn at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)rn at org.testng.TestNG.run(TestNG.java:1022)rn at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)rn at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)rn at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)rnCaused by: org.apache.ibatis.binding.BindingException: Parameter 'item' not found. Available parameters are [list]rn at org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap.get(DefaultSqlSession.java:254)rn at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:40)rn at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:123)rn at org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:83)rn at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:77)rn at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:58)rn at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:71)rn at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56)rn at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)rn at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141)rn at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)rn at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)rn ... 38 morernrnrn===============================================rn Default testrn Tests run: 1, Failures: 1, Skips: 0rn===============================================[/code]rnrn请各位大师帮忙看看如何解决。

没有更多推荐了,返回首页