spring整合Mybatis错误:Parameteritems_idnotfound.A。。。
  运⾏环境: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.ller.ItemsController.deleteItems(java.lang.Integer[]) throws java.lang.Exception]: batis.spring.MyBatisSystemException: nested exception is org.apache.ib
2 Resolving exception from handler [public java.lang.String com.ller.ItemsController.deleteItems(java.lang.Integer[]) throws java.lang.Exception]: batis.spring.MyBatisSystemException: nested exception is org.apache.ib
3 Resolving exception from handler [public java.lang.String com.ller.ItemsController.deleteItems(java.lang.Integer[]) throws java.lang.Exception]: batis.spring.MyBatisSystemException: nested exception is org.apache.ib
4 Could not complete request
batis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'items_id' not found. Available parameters are [array]
6 batis.anslateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
7 batis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
8 at com.sun.proxy.$Proxy11.delete(Unknown Source)
9 batis.spring.SqlSessionTemplate.delete(SqlSessionTemplate.java:268)
10 at org.apache.ibatis.ute(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 flect.NativeMethodAccessorImpl.invoke0(Native Method)
15 flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
16 flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17 at flect.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 ansaction.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.ller.ItemsController.deleteItems(ItemsController.java:109)
28 flect.NativeMethodAccessorImpl.invoke0(Native Method)
29 flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
30 flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
31 at flect.Method.invoke(Method.java:601)
32 at org.hod.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
33 at org.hod.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
34 at org.springframework.web.hod.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
35 at org.springframework.web.hod.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
36 at org.springframework.web.hod.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
37 at org.springframework.web.hod.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
mybatis和springmvc
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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
46 at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
47 at at.websocket.server.WsFilter.doFilter(WsFilter.java:51)
48 at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
49 at org.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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
53 at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
54 at org.apache.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
55 at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
56 at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
57 at org.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
58 at org.StandardContextValve.invoke(StandardContextValve.java:123)
59 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
60 at org.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.StandardEngineValve.invoke(StandardEngineValve.java:118)
64 at org.tor.CoyoteAdapter.service(CoyoteAdapter.java:408)
65 at http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
66 at AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
67 at at.util.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
68 at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
69 at urrent.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.java:261)
73 at org.apache.ltags.Property(DynamicContext.java:123)
74 at org.Property(OgnlRuntime.java:1657)
75 at org.ValueBody(ASTProperty.java:92)
76 at org.l.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
77 at org.Value(SimpleNode.java:210)
78 at org.Value(Ognl.java:333)
79 at org.Value(Ognl.java:413)
80 at org.Value(Ognl.java:395)
81 at org.apache.Value(OgnlCache.java:48)
82 at org.apache.ltags.ExpressionEvaluator.evaluateIterable(ExpressionEvaluator.java:39)
83 at org.apache.ltags.ForEachSqlNode.apply(ForEachSqlNode.java:54)
84 at org.apache.ltags.MixedSqlNode.apply(MixedSqlNode.java:32)
85 at org.apache.ltags.TrimSqlNode.apply(TrimSqlNode.java:54)
86 at org.apache.ltags.MixedSqlNode.apply(MixedSqlNode.java:32)
87 at org.apache.BoundSql(DynamicSqlSource.java:40)
88 at org.apache.ibatis.BoundSql(MappedStatement.java:278)
89 at org.utor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:64)
90 at org.utor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:39)
91 at org.utor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:45)
92 at org.apache.ibatis.wStatementHandler(Configuration.java:468)
93 at org.utor.SimpleExecutor.doUpdate(SimpleExecutor.java:46)
94 at org.utor.BaseExecutor.update(BaseExecutor.java:105)
95 at org.utor.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 flect.NativeMethodAccessorImpl.invoke0(Native Method)
99 flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
100 flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
101 at flect.Method.invoke(Method.java:601)
102 batis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
103 ... 63 more
  相关代码:
1<?xml version="1.0" encoding="UTF-8" ?>
2<!DOCTYPE mapper PUBLIC "-////DTD Mapper 3.0//EN" "/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 ⽂件
1package com.kjczwl.ssm.mapper;
2/**
3 *  items 的接⼝
4*/
5import java.util.List;
6import com.kjczwl.ssm.po.ItemsCustom;
7import com.kjczwl.ssm.po.ItemsQueryVo;
8public interface ItemsMapperCustom {
9/**
10    *    商品的查询這⾥的⽅法⾯和l ⾥⾯select id名⼀样
11    * @param itemsQueryVo
12    * @return返回⼀个ItemsCustom:扩展类
13    * @throws Exception
14*/
15public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo)throws Exception;
16/**
17    *  商品批量删除的
18    * @param items_id
19*/
20public void deleteItems(Integer[] items_id);
21
22/**
23    *  商品批量查询
24    * @param items_id
25*/
26public List<ItemsCustom> findEditItems(Integer[] items_id);
27
28 }

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。