mybatis-plus 3.5.6 tem o seguinte erro de acordo com a configuração do site oficial
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.niu.manager.mapper.DepartmentMapper.selectList
at org.apache.ibatis.binding.MapperMethod KaTeX parse error: Undefined control sequence: \[ at posição 43: …hod.java:235) ~\̲[̲mybatis-3.5.6.j… cachedInvoker$0(MapperProxy.java:115) ~[mybatis-3.5.6.jar:3.5.6]
em java.util. concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_211]
resolver
solução usual
-
Verifique a configuração @MapperScan(basePackages = " com.xxx.mapper ")
-
Verifique se o caminho de configuração de mybatis.mapper-locations: classpath: mapper/*.xml está correto
-
Preste atenção se há um arquivo mapper.xml no diretório de destino do projeto, caso contrário, adicione a seguinte configuração ao pom.xml
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 --> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
poço de mybatis puls
-
Pit: Você não pode usar o SqlSessionFactory integrado ao usar mybatis-plus. Para usar MybatisSqlSessionFactory, adicione a seguinte configuração (springboot) à classe de configuração
@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(); }