org.apache.ibatis.binding.BindingException 报错
大体原因:
Spring整合Mybatis出错
报错:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)…
解决:
- mapper.xml的命名空间(namespace)是否跟mapper接口的包名一致
- mapper接口和mapper.xml是否在同一个包(package)下(可能有些开发者习惯不一样,所以可以看接口和xml文件的位置信息)?名字是否一样(仅后缀不同,后缀不能省略)
- 接口中是否有@Mapper注解,方法名是否与xml中的sql的标签id一致
- 如果接口中的返回值List集合(不知道其他集合也是),那么xml里面的配置,尽量用resultMap(保证resultMap配置正确),不要用resultType
- 如果你的项目是maven项目,请你在编译后,到接口所在目录看一看,很有可能是没有生产对应的xml文件,因为maven默认是不编译的,因此,你需要在你的pom.xml的里面,加这么一段:
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
若是mybatis集成在springboot中时:在application.properties/application.yml添加配置代码: