异常信息
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.com.herion.cloud.mall.mysql.dao.TestDataMapper.selectById
异常原因
经过再三确认,MybatisPlus的基础配置是没有配错的。后来终于查到原因原来是项目中使用了多数据源,重写的时候写用了Mybatis的SqlSessionFactory而没有使用MybatisPlus的MybatisSqlSessionFactoryBean。
既然原因找到了,那么接下来的的解决就相对简单了
解决方法
@Configuration
public class MybatisPlusConfiguration {
/**
* 将SqlSessionFactory配置为MybatisPlus的MybatisSqlSessionFactoryBean
*
* @param dataSource 默认配置文件中的数据源
* @return MybatisSqlSessionFactoryBean
*/
@Bean("mpSqlSessionFactory")
public MybatisSqlSessionFactoryBean setSqlSessionFactory(DataSource dataSource) {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
// 设置数据源
bean.setDataSource(dataSource);
// 简化PO的引用
bean.setTypeAliasesPackage("cn.com.wdtrgf.cloud.mall.mysql.model.**");
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/mysql/**/*.xml"));
// 设置全局配置
bean.setGlobalConfig(this.globalConfig());
return bean;
}
/**
* 设置全局配置
*
* @return 全局配置
*/
public GlobalConfig globalConfig() {
GlobalConfig globalConfig = new GlobalConfig();
GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
// 设置逻辑删除字段
dbConfig.setLogicDeleteField("deleted");
// 设置更新策略
dbConfig.setUpdateStrategy(FieldStrategy.NOT_EMPTY);
globalConfig.setDbConfig(dbConfig);
return globalConfig;
}
}