1.MyBatis-Plus 无法使用 resources 目录下的 *Mpper.xml
mybatis-plus报错解决Invalid bound statement (not found)错误
项目结构:
报错原因:
mapper目录下的ExampleUserMapper
无法绑定resource/mapper/sys/ExampleUserMapper.xml
解决方案1:
检查代码是否存在 调整 SqlSessionFactory 为 MyBatis-Plus 的 SqlSessionFactory
的操作
将类似代码注释掉即可(使用)
如下:
public class MyBatisPlusConfig {
@Autowired
@Qualifier(value = "dataSource")
DataSource dataSource;
@Autowired
MybatisPlusInterceptor paginationInnerInterceptor;
@Bean("sqlSessionFactory")
MybatisSqlSessionFactoryBean bean() {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setPlugins(paginationInnerInterceptor);
return bean;
}
}
解决方案2:
在MybatisSqlSessionFactoryBean
中添加映射文件路径
public class MyBatisPlusConfig {
@Autowired
@Qualifier(value = "dataSource")
DataSource dataSource;
@Autowired
MybatisPlusInterceptor paginationInnerInterceptor;
@Bean("sqlSessionFactory")
MybatisSqlSessionFactoryBean bean() {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setDataSource(dataSource);
// 设置映射xml路径
bean.setMapperLocations(new ClassPathResource("mapper/sys/ExampleUserMapper.xml"));
bean.setPlugins(paginationInnerInterceptor);
return bean;
}
}