When integrating mybatis with springboot, an error of invalid bound statement (not found) is reported. After repeated changes and trial and error, it is found that mapper.xml cannot be scanned. The key lies in two aspects.
-
- if you put XML in the Java directory, you need to configure the path in the POM package
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/sqlmap/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
-
-
- add the statement of scan mapping file to mybatis configuration class
-
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sessionFactory.setMapperLocations(resolver.getResources("classpath*:**/sqlmap/*.xml"));//扫描映射文件
-
-
-
- if the mapper.xml file is placed in the resources directory, maperlocations should be configured in application.yml
-
-
mybatis:
mapper-locations: classpath:mapping/*.xml #Note: Be sure to correspond to the path where the mapper mapping xml file is located
Read More:
- [Solved] Mybatis-Plus Error: Invalid bound statement (not found)
- How to Solve Mybatis error: invalid bound statement (not found)
- Mybatis Error: Invalid bound statement (not found)
- How to Solve Error: 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
- Ternary operator in Java?: error: not a statement
- [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
- HQL statement query error: could not resolve property [Solved]
- [Solved] Mybatis Batch Modify Error: multi-statement not allow
- [Solved] Springboot error: Could Not Found xxmapper
- [Solved] The war package Error: The reason why the XSD file could not be found
- 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] Invalid Gradle JDK configuration found. Open Gradle Settings Change JDK location
- Error: unreachable statement [How to Solve]
- Mybatis plus configuration console prints complete SQL statement with parameters
- springboot jsp: There was an unexpected error (type=Not Found, status=404). No message available
- [Solved] IDEA error: sun.security.pkcs not found
- [Solved] itextpdf Read PDF File Error: Rebuild failed: trailer not found.
- [Solved] Project Error: Could not found sun.misc.BASE64Encoder