今天使用MyBatis的过程中遇到一个奇怪的错误,错误信息提示“参数个数不匹配”,不过我对了几遍Service、Mapper、Mapper.xml中的参数都没有发现问题。
后面注意到,在错误提示的第一行中还有一句“Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #12 with JdbcType null.”。经查阅,原来是因为在Mapper.xml文件中,我使用了快捷键“Ctrl+\”对几行语句进行了单行注释(-- 语句 --),而该处的注释必须使用“<!-- -->”这种注释形式。
此外,今天还犯了一些很无脑的错误,比如说,Mapper.xml文件中使用mapper标签的namespace属性对应Mapper接口与Mapper.xml文件时,使用insert标签的parameterType属性指定元素类型时,因为包名写错导致错误。比如说,Mapper.xml使用insert标签时,将id定义为“insertToMysql”,而在Service、Mapper接口中方法名为“insertToMySQL”,因此出现了“org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxx.DownloadMapper.insertToMySQL”的异常。
此外,在Service类中使用“@Autowired”注入Mapper时,提示“Can not autowire. No beans of 'DownloadMapper' type found”,但是,实际上是不影响运行的。可以参考,https://blog.csdn.net/u012453843/article/details/54906905/
参考: