Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]

問題描述:

通過 #{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));
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章