Invalid bound statement (not found)
异常先检查mapper和xml文件的对应关系
然后检查xml文件里的namespace路径是否正确
然后检查resources中yml文件的配置是否正确
然后在pom文件中进行配置
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
其实上边这些,一般是不会犯错的,真的,因为一些人是用代码生成器生成的,是不可能犯这些错的,那么其实,你犯的错真的有可能是jar包依赖冲突了
你一定要细心去找你的jar包是不是存在依赖冲突。是的话就排除掉
很有可能是myabtis plus的jar包冲突了
检查 Mapper.java 的扫描路径
Configuration
类上使用注解 MapperScan
@Configuration
@MapperScan("com.yourpackage.*.mapper")
public class YourConfigClass{
...
}
Configuration
类里面,配置MapperScannerConfigurer
(查看示例 (opens new window))@Bean
public MapperScannerConfigurer mapperScannerConfigurer(){
MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer();
//可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了
scannerConfigurer.setBasePackage("com.yourpackage.*.mapper");
return scannerConfigurer;
}
检查是否指定了主键?如未指定,则会导致 selectById
相关 ID 无法操作,请用注解 @TableId
注解表 ID 主键。当然 @TableId
注解可以没有!但是你的主键必须叫 id(忽略大小写)
SqlSessionFactory不要使用原生的,请使用MybatisSqlSessionFactory
检查是否自定义了SqlInjector,是否复写了getMethodList()方法,该方法里是否注入了你需要的方法(可参考DefaultSqlInjector)
出现 `Invalid bound statement (not found)` 异常
原文:https://www.cnblogs.com/coderD/p/14394263.html