mybatis plus 常见问题Invalid bound statement (not found)解决方法汇总
Invalid bound statement(not found)
·
mybatis plus 常见问题Invalid bound statement (not found)解决方法汇总
一、问题描述
出现 Invalid bound statement (not found) 异常。
二、解决方法汇总
- 检查xml的namespace是否和xml文件的package名称一一对应;
- 检查xml中是否使用了type别名,如果用了别名,检查下别名包名是否配置正确,如果不确定,可以将实体类全包名加上去,还有就是看下实体类里面是否使用了typeHandler类型处理器,如果使用了,记得将完整包名加上去;
3.xxxMapper.java的方法返回值是List,而select元素没有正确配置ResultMap,或者只配置ResultType;
4.Mapper.xml不存在,一般mapper.xml会放在源码目录下,或resources目录下,检查mapper.xml打包后,在target/classes目录下是否存在; - 注意mybatis/mybatis plus配置与@MapperScan 注解;
- 检查是不是引入 jar 冲突 如 mybtatis-plus springboot可以使用引入
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
;
- 如果以上还没有解决查看 mybatis-plus的SqlSessionFactory不要使用原生的,请使用MybatisSqlSessionFactory。如下
@Bean(name = "sqlSessionFactory")
@Primary
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource datasource)
throws Exception {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setDataSource(datasource);
bean.setPlugins(mybatisPlusInterceptor());
System.out.println("bean = " + bean.toString());
return bean.getObject();
}
- 最后请查看mapper.xml的名称与mapper.java名称是否一致。
更多推荐
已为社区贡献1条内容
所有评论(0)