运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse
错误:Parameter 'items_id' not found. Available parameters are [array]
错误原因:这是个批量删除案例,从页面传递数组到controller,在我的mapper里面映射错误,我的错误已经在下面标识出来。
解决办法:错误意思已经很清楚了,参数items_id 没有找到,可用参数 array,将items_id 修改成array 这里才能接受得到controller 传过来的数组
错误代码:
1 Resolving exception from handler [public java.lang.String com.kjczwl.ssm.controller.ItemsController.deleteItems(java.lang.Integer[]) throws java.lang.Exception]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'items_id' not found. Available parameters are [array] 2 Resolving exception from handler [public java.lang.String com.kjczwl.ssm.controller.ItemsController.deleteItems(java.lang.Integer[]) throws java.lang.Exception]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'items_id' not found. Available parameters are [array] 3 Resolving exception from handler [public java.lang.String com.kjczwl.ssm.controller.ItemsController.deleteItems(java.lang.Integer[]) throws java.lang.Exception]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'items_id' not found. Available parameters are [array] 4 Could not complete request 5 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'items_id' not found. Available parameters are [array] 6 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) 7 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) 8 at com.sun.proxy.$Proxy11.delete(Unknown Source) 9 at org.mybatis.spring.SqlSessionTemplate.delete(SqlSessionTemplate.java:268) 10 at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57) 11 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) 12 at com.sun.proxy.$Proxy12.deleteItems(Unknown Source) 13 at com.kjczwl.ssm.service.impl.ItemsServiceImpl.deleteItems(ItemsServiceImpl.java:59) 14 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 15 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 16 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 17 at java.lang.reflect.Method.invoke(Method.java:601) 18 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) 19 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 20 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 21 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 22 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 23 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) 24 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 25 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 26 at com.sun.proxy.$Proxy15.deleteItems(Unknown Source) 27 at com.kjczwl.ssm.controller.ItemsController.deleteItems(ItemsController.java:109) 28 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 29 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 30 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 31 at java.lang.reflect.Method.invoke(Method.java:601) 32 at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) 33 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 34 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) 35 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746) 36 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687) 37 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 38 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) 39 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 40 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915) 41 at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:822) 42 at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 43 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) 44 at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 45 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 46 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 47 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) 48 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 49 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 50 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 51 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 52 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 53 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 54 at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66) 55 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 56 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 57 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 58 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 59 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 60 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 61 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 62 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 63 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 64 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 65 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) 66 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) 67 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) 68 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 69 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 70 at java.lang.Thread.run(Thread.java:722) 71 Caused by: org.apache.ibatis.binding.BindingException: Parameter 'items_id' not found. Available parameters are [array] 72 at org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap.get(DefaultSqlSession.java:261) 73 at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:123) 74 at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657) 75 at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92) 76 at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170) 77 at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210) 78 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333) 79 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413) 80 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395) 81 at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:48) 82 at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateIterable(ExpressionEvaluator.java:39) 83 at org.apache.ibatis.scripting.xmltags.ForEachSqlNode.apply(ForEachSqlNode.java:54) 84 at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32) 85 at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:54) 86 at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32) 87 at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:40) 88 at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:278) 89 at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:64) 90 at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:39) 91 at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:45) 92 at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:468) 93 at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:46) 94 at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105) 95 at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71) 96 at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152) 97 at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:165) 98 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 99 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 100 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 101 at java.lang.reflect.Method.invoke(Method.java:601) 102 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358) 103 ... 63 more
相关代码:
mapper.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> 3 <mapper namespace="com.kjczwl.ssm.mapper.ItemsMapperCustom" > 4 <!-- 定义商品查询的sql片段,也就是商品查询条件 --> 5 <sql id="query_items_where"> 6 <!-- 使用动态sql,通过if判断,满足条件进行sql拼接 --> 7 <!-- 商品查询条件通过ItemsQueryVo包装对象中itemsCustom属性传递 下面使用到sturts 的ognl--> 8 <if test="itemsCustom!=null"> 9 <if test="itemsCustom.name!=null and itemsCustom.name!=''"> 10 items.name LIKE '%${itemsCustom.name}%' 11 </if> 12 </if> 13 </sql> 14 15 <!-- 商品列表查询 16 parameterType: 传入一个包装对象(包装了查询条件)(重点 包装类) 17 parameterMap: 建议使用扩展对象 18 --> 19 <select id="findItemsList" parameterType="com.kjczwl.ssm.po.ItemsQueryVo" resultType="com.kjczwl.ssm.po.ItemsCustom"> 20 SELECT * from items 21 <where> 22 <!-- 导入上面的sql片段 --> 23 <include refid="query_items_where"/> 24 </where> 25 </select> 26 <delete id="deleteItems" parameterType="java.lang.Integer" > 27 delete from items 28 <where> 29 id in 30 <foreach collection="items_id" item="item" index="index" open="(" separator="," close=")"> 31 #{item} 32 </foreach> 33 </where> 34 </delete> 35 <select id="findEditItems" parameterType="java.lang.Integer" resultType="com.kjczwl.ssm.po.ItemsCustom"> 36 select * from items 37 <where> 38 id in 39 <foreach collection="items_id" index="index" item="item" open="(" separator="," close=")" > 40 #{item} 41 </foreach> 42 </where> 43 </select> 44 </mapper>
对应的mapper.java 文件
1 package com.kjczwl.ssm.mapper; 2 /** 3 * items 的接口 4 */ 5 import java.util.List; 6 import com.kjczwl.ssm.po.ItemsCustom; 7 import com.kjczwl.ssm.po.ItemsQueryVo; 8 public interface ItemsMapperCustom { 9 /** 10 * 商品的查询 這里的方法面和ItemsMapperCustom.xml 里面select id名一样 11 * @param itemsQueryVo 12 * @return 返回一个ItemsCustom:扩展类 13 * @throws Exception 14 */ 15 public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo)throws Exception; 16 /** 17 * 商品批量删除的 18 * @param items_id 19 */ 20 public void deleteItems(Integer[] items_id); 21 22 /** 23 * 商品批量查询 24 * @param items_id 25 */ 26 public List<ItemsCustom> findEditItems(Integer[] items_id); 27 28 }