使用MyBatis进行查询操作,在DAO层中参数类型传的是一个List
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'list' not found. Available parameters are [thirddptList, userId, param1, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:160)
at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:120)
at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)
at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395)
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:45)
at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateIterable(ExpressionEvaluator.java:36)
at org.apache.ibatis.scripting.xmltags.ForEachSqlNode.apply(ForEachSqlNode.java:51)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:29)
at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:37)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:275)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:79)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
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:358)
... 96 more
2.错误说明
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'list' not found. Available parameters are [thirddptList, userId, param1, param2]
原因:org.apache.ibatis网站.binding.BindingException绑定异常:找不到参数“list”。可用参数为[thirdptlist,userId,param1,param2]
DAO层
public List queryRuleBatchExcelthirdby(
@Param("userId")String userId,
@Param("thirddptList") List thirddptList
);
XML层
传递一个 List 实例或者数组作为参数对象传给 MyBatis,MyBatis会自动将它包装在一个Map中,用名称在作为键。List 实例将会以“list” 作为键,而数组实例将会以“array”作为键。因为我传的参数是一个List集合,所以mybatis会自动封装成Map<"list",thirddptList>;在解析的时候会通过“list”作为Map的key值去查找,但是我在DAO中却声明的是thirddptList,所以自然会报错找不到参数“list”。其实collection类型应该要和我们定义的@Param绑定的参数名一致。
XML层中foreach里面的collection类型要和DAO层中@Param绑定的参数名相一致
DAO层
XML层