mybatis-plus 3.5.6按照官网的配置出现了如下错误
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.niu.manager.mapper.DepartmentMapper.selectList
at org.apache.ibatis.binding.MapperMethodKaTeX parse error: Undefined control sequence: \[ at position 43: …hod.java:235) ~\̲[̲mybatis-3.5.6.j…cachedInvoker$0(MapperProxy.java:115) ~[mybatis-3.5.6.jar:3.5.6]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_211]
解决
通常解决办法
-
检查配置@MapperScan(basePackages = “com.xxx.mapper”)
-
检查mybatis.mapper-locations: classpath:mapper/*.xml的配置路径是否正确
-
注意项目的target目录下是否有mapper.xml文件,如果没有则要在pom.xml加入如下配置
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 --> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
mybatis puls的坑
-
坑:使用mybatis-plus时不能使用自带的SqlSessionFactory,要使用MybatisSqlSessionFactory,在配置类中加入如下配置(springboot)
@Primary @Bean("db1SqlSessionFactory") public SqlSessionFactory db1SqlSessionFactory(DataSource dataSource) throws Exception { /** * 使用 mybatis plus 配置 */ MybatisSqlSessionFactoryBean b1 = new MybatisSqlSessionFactoryBean(); System.out.println("dataSourceLyz"+dataSource.toString()); b1.setDataSource(dataSource); b1.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); return b1.getObject(); }