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:
- [Solved] Mybatis-Plus Error: Invalid bound statement (not found)
- How to Solve Error: Invalid bound statement (not found)
- Mybatis Error: Invalid bound statement (not found)
- [How to Solve] Invalid bound statement (not found)
- Springboot mybatis Integrate Error: Invalid bound statement (not found): com…DepartmentMapper.save
- There was an unexpected error (type=Internal Server Error, status=500).Invalid bound statement (not
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- [Solved] Mybatis Batch Modify Error: multi-statement not allow
- How to Solve mybatis-plus Paging Plug-in PaginationInnerInterceptor error
- How to Solve SQL comments error in the mybatis query
- Mybatis plus configuration console prints complete SQL statement with parameters
- Using mybatis statement.getGenreatedKeys(); usegeneratedkeys = “true”; using self incrementing primary key to get primary key value policy and Oracle do not support self incrementing, Oracle uses sequence
- [Solved] Mybatis.generator error: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2
- How to Solve Error: No suitable driver found for
- Mybatis single parameter pass in exception (How to Fix)
- Mybatis-plus: How to Execute Native SQL
- [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
- [Solved] Tk-Mybatis Error: tk.mybatis.mapper.MapperException:
- How to Solve Flick operate Error: not serialized
- Mybatis sets the primary key Auto-Increment error: No setter found for the keyProperty