Mybatis plus calls its own method and reports an error invalid bound statement
1. Check for version conflicts
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.4.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>3.4.3</version>
<scope>compile</scope>
</dependency>
2. Check the path and namespace correspondence
Check scan compile path
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapping/publicDB/**/*.xml"));
or
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
Check the incoming basemapper path
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
Check the namespace and function name correspondence of the XML file to ensure that no error is reported during compilation, and remove the Chinese comments in the XML file
3. Use mybatissqlsessionfactory
/**
* Create SqlSessionFactory
*/
@Bean(name = "primarySqlSessionFactory")
@Primary
public SqlSessionFactory testSqlSessionFactory(@Qualifier("primaryDataSource") DataSource dataSource) throws Exception {
// Do not use the original of SqlSessionFactory instead of using MybatisSqlSessionFactory
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapping/publicDB/**/*.xml"));
return bean.getObject();
}
Mybatisplusconfig configuration class configured in the original blog post:
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.MybatisXMLLanguageDriver;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.plugin.Interceptor;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
@Configuration
public class MybatisPlusConfig {
@Autowired
private DataSource dataSource;
@Autowired
private MybatisProperties properties;
@Autowired
private ResourceLoader resourceLoader = new DefaultResourceLoader();
@Autowired(required = false)
private Interceptor[] interceptors;
@Autowired(required = false)
private DatabaseIdProvider databaseIdProvider;
/** mybatis-plus */
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor page = new PaginationInterceptor();
page.setDialectType("mysql");
return page;
}
/** All resources that are already loaded automatically by mybatis-autoconfigure are used here. Instead of manually specifying the <p> configuration file and mybatis-boot's configuration file synchronization @return */
@Bean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
mybatisPlus.setDataSource(dataSource);
mybatisPlus.setVfs(SpringBootVFS.class);
if (StringUtils.hasText(this.properties.getConfigLocation()))
mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
if (!ObjectUtils.isEmpty(this.interceptors)) mybatisPlus.setPlugins(this.interceptors);
MybatisConfiguration mc = new MybatisConfiguration();
mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
// Database field design for hump naming, the default open hump to underscore will report an error field can not be found
mc.setMapUnderscoreToCamelCase(true);
mybatisPlus.setConfiguration(mc);
if (this.databaseIdProvider != null) mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
if (StringUtils.hasLength(this.properties.getTypeAliasesPackage()))
mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
if (StringUtils.hasLength(this.properties.getTypeHandlersPackage()))
mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations()))
mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
return mybatisPlus;
}
}
Read More:
- mybatis-plus calls its own selectById method and reports an error: org.apache.ibatis.binding.BindingException:
- Mybatis error under Springboot project: Invalid bound statement (not found)
- [Solved] mybatis plus Error: Invalid bound statement (not found)
- [Solved] Mybatis-plus Error: mybatisplus-Invalid bound statement (not found): com.integration.dao.ApiDao.getList
- How to Solve org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) Error
- Ise14.7 uses its own XST synthesis Error: error: ngdbuild: 604
- SpringBoot uses MyBatis error: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)
- Kafkaconsumer calls seek() method error [How to Solve]
- [Solved] Mybatis Error: Resources.getResourceAsStream(resource) cannot find the method
- [Solved] Mybatis uses the PageHelper paging plugin error: Could not find method on interface ibatis.executor.Executor named query.
- [Solved] Mybatis crud insert error: org.apache.ibatis.binding.BindingException: Mapper method ‘com.liang.dao.UserMapper.addUser…
- [Solved] Springboot Reflection calls ServiceImpl Error: java.lang.NullPointerException, mapper is null
- Mybatis Error: Result Maps collection already contains value
- [Solved] Mybatis Error: CannotFindDataSourceException: dynamic-datasource can not find primary datasource
- QT calls the API of ffmpeg error [How to Solve]
- How to Fix HTTP Error 500: the default page enter their own routing can’t find a result
- Hive Statement Error During Execution: Error while processing statement: FAILED: Execution Error, return code 2 from o
- [Solved] the request was rejected because its size (11579386) exceeds the configured maximum (10485760)
- Error: array bound is not an integer constant before ‘]’ token
- How to Solve Keras calls plot_model error