问题描述:
通过 #{index} 索引方式接收参数报错,如:#{0} #{1}
错误信息:
nested exception is org.apache.ibatis.binding.BindingException: Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
问题排查:
3.4.1以及之前版本可以使用 #{index},如:#{0} #{1} #{2} ……
3.4.2以及之后版本由 #{index} 改为用 #{arg0} #{arg1}... 代替
原因分析:
MyBatis的通过XMLConfigBuilder类来加载配置文件中的各项参数
- 3.4.1以及之前版本设置属性中useActualParamName参数的默认值为flase
XMLConfigBuilder.class的settingsElement方法中的源代码
configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
- 3.4.2以及之后版本设置属性中useActualParamName参数的默认值为true
XMLConfigBuilder.class的settingsElement方法中的源代码
configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), false));
博客围绕MyBatis接收多个参数时,通过 #{index} 索引方式接收参数报错的问题展开。指出3.4.1及之前版本可用 #{index},3.4.2及之后版本需用 #{arg0} #{arg1} 代替。还分析了原因,即不同版本中useActualParamName参数默认值不同。
1457

被折叠的 条评论
为什么被折叠?



