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

Mybatis plus reports an error: invalid bound statement (not found)

After integrating mybatis plus in the spring boot project, it is found that the user-defined query method will report an error: “invalid bound statement (not found): * * *.” your method “, which means that your user-defined method cannot be found in the XML file. Various methods are tried and the problem is finally solved. This problem exists in the following situations:

1. Mapper file and XML file cannot correspond

1. Check whether mapper file and XML file names are consistent

UserMapper and UserMapper.xml

2. Check whether the attribute configuration of namespace in the XML file corresponds to the corresponding mapper file

<mapper namespace="com.*.*.mapper.UserMapper">

3. Check whether the method binding ID in the XML file is consistent

    List<User> getUserList();
    <select id="getUserList" resultType="com.*.*.entity.User">
        SELECT * FROM user

2. The XML file is placed in the resources directory at different levels and is not packaged into the target

By default, all will be packaged. Check whether the property of not packaging is configured in the POM file, and modify it

Note: this configuration is to package the resources directory and check the differences

        <!-- Pack the files in the resources directory -->

(focus on configuration, which is also my problem) third, the XML file is placed in the resources directory at different levels and has been packaged into the target, but the corresponding method cannot be found

It is thought that after packaging, you can match according to the name. Finally, it is found that even if the XML file is packaged, it still belongs to a different level from mapper, so check whether the mybatis plus configuration matching the location of the XML file is missing

mybatis-plus.mapper-locations = classpath:mapping/*.xml
# The "mapping" in this configuration corresponds to the name of the directory where your xml is located

Read More: