mybatis新增传一个对象参数和一个引用类型参数(org.apache.ibatis.binding.BindingException:Parameter 'XXX' not found. Available parameters are [user, param1, key, param2])
先上报错信息
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'userID' not found. Available parameters are [user, param1, key, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:209)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:79)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:94)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:87)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 28 common frames omitted
再上mapper代码
如果只有一个user对象,这样传参是是没问题的,但是我后面新增了一个@Param(“key”) String key,就会报上面的错误
解决方案
很简单,在每个#{}内加入mapper接口用@Param定义的参数名:user就可以了,key的名称也是使用@Param内定义的参数名:key