问题描述:
MybatisPlus自带方法如 xxx.list() xxx.save() 或则xxMapper.selectList()...
等方法无法使用报错:Invalid bound statement (not found)
但是自己定义的sql方法可以使用
问题排查:
1、自定义方法可使用 排除xml位置不正确,包扫描没扫到(target目录下已生成对应的mapper和xml文件)
2、检查mybatis-plus.mapper-locations=classpath:mapper/*/*.xml 配置没问题
3、检查自定义配置代码:
@Bean(name = "mysqlSqlSessionFactory") public SqlSessionFactory mysqlSqlSessionFactory(@Qualifier("mysqlDataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/mysql/*.xml")); return bean.getObject(); }
找到问题:SqlSessionFactory是MyBatis的类,MybatisPlus应该使用MybatisSqlSessionFactoryBean
问题修复:
@Bean(name = "mysqlSqlSessionFactory") public MybatisSqlSessionFactoryBean mysqlSqlSessionFactory(@Qualifier("mysqlDataSource") DataSource dataSource) throws Exception { MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/mysql/*.xml")); return bean; }
未经允许 禁止转载
标签:xml,mapper,MybatisPlus,bean,报错,statement,new,mysqlSqlSessionFactory From: https://www.cnblogs.com/axibug/p/18343323