MyBatis:Invalid bound statement (not found)

Mybatis reports an error: Invalid bound statement (not found), there are many reasons, but just like the error message, the SQL statement in the xml cannot be found. There are three types of error reports:

The first type: syntax error

Java DAO layer interface

public void delete(@Param("id")String id);

Java corresponding mapper.xml file

 

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="xxx.xxx.xxx.Mapper"> <!-- 删除数据 --> <delete id="delete" parameterType="java.lang.String"> DELETE FROM xxx WHERE id=#{id} </delete> </mapper>

 

Check: 1. Whether the method name (delete) in the interface is consistent with id="delete" in the xml file

   2. Whether the path in namespace="xxx.xxx.xxx.Mapper" in the xml file is consistent with the interface file path

   3. Whether the parameterType and resultType are accurate; resultMap and resultType are different.

The second: compilation error

  Locate the project path: under the error path in target\classes\, and look for the corresponding xml file.

(1) If there is no corresponding xml file, you need to add the following code in pom.xml:

 

<build> <resources> <resource> <directory>src/main/java</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </resource> </resources>
</build>

 

  Delete the files in the classes folder, recompile, and the corresponding xml file will appear.

(2) If there is an xml file, open the xml file and check whether the error part is consistent with the source file.

  First clear the files in the classes folder, execute the command: mvn clean to clean up the content, and then recompile.

The third type: configuration error

  When specifying the scan package in the configuration file, there is a problem with the configuration path. For example: the "basePackage" attribute package name specified in the spring configuration file must be specific to the package where the interface is located, instead of writing the parent or higher level package, otherwise problems may occur; cn.dao and cn.* may also cause errors ; When the annotation is scanned, the package may not be scanned.

Guess you like

Origin blog.csdn.net/u013821237/article/details/104171553