BindingException: Invalid bound statement (not found): com.XX.EduChapterMapper solution appears

Error scenario:

I believe that you may often encounter this error when writing sql statements in mybatis, and it is recorded here for reference only.

Program error: "  org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxx.xxx  "


Cause Analysis:

The exception prompts that in the use of the MyBatis-Plus persistence framework, the binding between Mapper.java and Mapper.xml fails, and the binding relationship is wrong, so we naturally think whether the mapping name, return type or namespace of the mybatis method is wrong. If the comparison is correct, we must consider whether our mapping path is correct.


solution:

First of all: To confirm that there is no problem with your project construction, you can clean maven and refresh it again. If there is still an error, proceed to the next step.

Step 2: Check whether the address pointed to by your own namespace is correct. As shown in the picture below: (You can click CTRL + left mouse button to see if you can jump)

Step 3: Check whether the method name mapping and return object in mapper.xml are consistent with mapper.java. As shown below:

 Also here you can click on CTRL + left mouse button to see if you can jump

Step 4: Check the storage location of your mapper.xml (I am here)

If your mapper stores the image below like mine, you need to configure it in the pom file. This is because maven only recognizes java files under the java package by default. 

 The pom.xml code is as follows:

    <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

 Because my mapper.xml is placed under /mapper/xml , and mapper.java is placed under /mapper . They do not belong to the same level of directory, so they need to be configured in application.yml . If your mapper.xml and mapper.java are in the same directory, there is no need to operate. code show as below:

# Change the path to your own mapper.xml path 
mybatis-plus: 
  mapper-locations: classpath:com/xin/eduservice/mapper/xml/*.xml

So far, the operation is successful. The solution to org.apache.ibatis .binding.BindingException : Invalid bound statement (not found): com.xxx.xxx is written here. If you have any questions or encounter any problems, please leave a message in the comment area

Guess you like

Origin blog.csdn.net/weixin_58403235/article/details/129830264