[Solved] Mybatis Error: Invalid bound statement (not found)

Mybatis error reporting: there are many reasons for invalid bound statement (not found), but just like the error reporting prompt, the SQL statement in XML cannot be found. There are three types of error reporting:

The first: syntax error

Java Dao layer interface

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

Mapper.xml file corresponding to Java

<?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 Datas -->
    <delete id="delete" parameterType="java.lang.String">
        DELETE FROM xxx WHERE id=#{id}


Is the method name (delete) in the interface consistent with id = "delete" in the XML file

Is the path in namespace = "XXX. XXX. XXX. Mapper" in the XML file consistent with the path in the interface file

Whether the parametertype type and resulttype types are accurate; Resultmap is different from resulttype


Second: compilation error

Navigate to the project path: under the error path in target \ classes \ , find out whether the corresponding XML file exists

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


Delete the files in the classes folder, recompile, and the corresponding XML file appears

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

first clear the files in the classes folder and execute the command: MVN clean clean the content and recompile it


Third: configuration error

There was a problem with the configuration path when specifying the scan package in the configuration file

for example, : the package name of the “basepackage” attribute in the spring configuration file must be specific to the package where the interface is located, and do not write the package of the parent level or higher, otherwise problems may occur; Cn. Dao and CN. * may also cause errors; During annotation scanning, packages may not be scanned

Similar Posts: