Solve the mybatis error invalid bound statement (not found)
Reason for this error
1. XML file does not exist
2. The XML file and mapper are not mapped
Namespace specifies the path of mapper. The error ID is inconsistent with the method name in mapper
3. The XML file is in the Java directory instead of the resource directory, so there is no XML in the generated target
Scene
When using the mybatis plus framework, when customizing the mapper interface and XM file, because the MP automatic code generation plug-in is used, the mapper interface and XML file are in the Java directory. During compilation, the XML file under the Java path will not be automatically compiled, and the compilation will only identify the. Java file, Only XML files under resource can be compiled when packaged.
The following figure shows the XML and mapper directories of the MP auto generated code plug-in (no longer in the resource)
The compiled target directory is as follows:
Solution:
1. Add in POM file
<build>
<!-- The *.xml file in the java directory will also be packaged when the project is packaged -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
2. Manually move the XML file in the Java directory to the resource directory and add it to the configuration file in spring boot
mybatis-plus:
mapper-locations: classpath:**/*.xml //After the classpath add the directory of your xml file
The directory in mapper locations must be consistent with the directory where you place XML files, otherwise this error will occur even if there are XML files in target!!!
Read More:
- [How to Solve] Invalid bound statement (not found)
- [Solved] Mybatis-Plus Error: Invalid bound statement (not found)
- [Solved] ### Error building SqlSession. ### The error may exist in com/atguigu/dao/SysUserMapper.xml ### Caus
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- There was an unexpected error (type=Internal Server Error, status=500).Invalid bound statement (not
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could [Solved]
- [Solved] SpringBoot Error: Property ‘mapperLocations‘ was not specified.
- Cannot resolve reference to bean ‘sqlSessionFactory‘ while setting bean property ‘sqlSessionFactory‘
- [Solved] Could not find resource COM / atguigu / Dao / studentdao.xm, the mapper file for storing SQL statements could not be found and an error occurred
- Resources is configured in the build of Maven project to prevent the failure of resource export
- [Solved] BindingException: Type interface XXX is not known to the MapperRegistry
- [Maven] maven filtering OTS parsing error incorrect file size in WOFF head [Two Methods to Solve]
- Mybatis Error: Invalid bound statement (not found)
- Mybatis query error: Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException…
- Build a mybatis and it will appear session.selectOne Method error
- How to Solve Error: Invalid bound statement (not found)
- [Solved] org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession…
- Idea create Maven project Error: [error] no longer supports source option 1.5. Please use version 1.6 or higher, and the idea reports an error: error: Java does not support the error of release version 5
- [Solved] Read the resources resource and convert it to file error: java.io.filenotfoundexception