[SpringBoot+MyBatis] Invalid bound statement (not found) error in the project

1. Note: My mapper.xml is in the static resources resources folder.

2. Reason for error reporting:

1. The location of the Mapper.xml file is not configured correctly in the MyBatis configuration file or the wrong location is configured (My own problem)

Solution: Add mapper-locations in application.yml.

mybatis:
  mapper-locations: classpath:mapper/*.xml

This code is a tag in the MyBatis configuration file, used to specify the location of the Mapper XML file. Among them, mapper-locations is the attribute name, and classpath:mapper/*.xml is the attribute value.

Hereclasspath: means to start searching from the class path, and mapper/*.xml means to search for all the suffix .xml in the mapper directory under the class path. file and use it as a Mapper XML file. Normally, Mapper XML files are placed in a separate directory for management and maintenance.

2. The namespace in mapper.xml is inconsistent with the actual mapper file.

Solution: Right-click UserMapper ——》Copy Path/Prference ——》Copy Prference to copy the namespace path.

 3. The method name in the mapper interface is inconsistent with the id tag in mapper.xml

Solution: Check whether the id tag and method name are the same.

 4. Mapper.xml is not built.

Solution: Check in the target directory to see if the corresponding Mapper.xml file is there. If it is not there, click maven on the right, clean it, and run it again.

Guess you like

Origin blog.csdn.net/weixin_52060913/article/details/131078025