Remember a pit, about the Invalid bound statement (not found) error reported during the use of Mybatis

@[TOC](Mybatis reported an error during IDEA use: Invalid bound statement (not found))

1. The main code of the problem description:

ERROR com.cloud.utils.RRExceptionHandler - Invalid bound statement (not found): com.cloud.dao.affairs.MaterialCatalogDao.queryList
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.cloud.dao.affairs.MaterialCatalogDao.queryList

2. Problem analysis

Explanation : It means that after the Mapper interface of your dao layer is injected by Spring, it cannot normally use the defined SQL corresponding to the mapper.xml (which method specifies the specific SQL);

The Spring injection here means that your interface has been successfully scanned, but when Spring tries to inject a proxy (implemented by MyBatista) implementation class, it cannot be used normally. The possible situations here are as follows:

  1. The interface has been scanned, but the proxy object is not found. Even if you try to inject, it will still inject a wrong object (may be null)
    2. The interface has been scanned, and the proxy object is found, and it is injected into the interface, but it calls a certain When a specific method is used, it cannot be used (maybe other methods are normal)

3. Troubleshoot ideas

1. Are the mapper interface and mapper.xml in the same package? Are the names the same (only the suffix is ​​different)?
For example:
Wrong wording:
Insert picture description here
Insert picture description here
these two cannot be mapped

You can look at the correct writing, and avoid it in the future.
Correct writing: 1. The package name is the same, and the class name is the same as the mapping file name
Insert picture description here
Insert picture description here
(that is, the ****.xml file mapped by the dao layer and the ****.java file name are the same, And the path of the package is the same),

2. Is the namespace of mapper.xml consistent with the package name of the mapper interface?

3. Is the method name of the interface consistent with the id of a sql tag in xml?

4. Check whether the specified scan path is written in springboot, similar to the following code:

spring:
  mybatis:
    mapper-locations: com.cloud.dao.*.xml  #注意:一定要对应mapper映射xml文件的所在路径
    type-aliases-package: com.cloud.entity  # 注意:对应实体类的路径

Other matters :
There may be other omissions, please move to CSDN to search.

ε=(´ο`*))) Alas, what I encountered here is the first one. I didn’t expect to use the reverse generation method all the time. Suddenly a brother in the project hand-written the relevant dao layer and service layer, but did not notice The naming requirements between the java interface and the mapping file (really black under the light), I hope other people will not cause a mental explosion because of this, I wish a healthy life every day~~

Guess you like

Origin blog.csdn.net/rao991207823/article/details/107649296