Org.apache.ibatis.exceptions.PersistenceException error daily solution analysis

Analysis
Most of the org.apache.ibatis.exceptions.PersistenceException problems occur because the mapping file cannot be found, which is related to the failure to follow the mapper proxy configuration specification of mybatis.
For example:
1. There is a problem with reading and writing files, and the system cannot find this file

2. Whether the name of the mapper interface is the same as that of the mapped mapper.xml, and whether they are in the same directory.

3. There is an error in the path of the SqlMapConfig.xml configuration file loading the mapper interface file (generally there are two methods, the first scan

The second type of batch scan loading: select scan package <package name="package name" />)

4. When using the mapper proxy method to develop the mapper interface, the namespace in mapper.xml is consistent with the classpath of the mapper interface

At the same time, if you forget to write the namespace, the exception will also be reported.
5. If the type of resultMap in mapper.xml uses the entity class name, the package name must also be written in it.
6. When developing mybatis dynamic proxy, pay attention to four development specifications:

1.接口 方法名 == User.xml 中 id 名

2. 返回值类型 与 Mapper.xml文件中返回值类型要一致

3.方法的入参类型 与Mapper.xml中入参的类型要一致

4.命名空间 绑定此接口

Seeing these original basic analysis, you will have a little understanding of your own mistakes: the mapping file cannot be found
because I do not have a mapper.xml file for my own framework, so the above detailed errors are not my fault. Under the Springboot framework, first create the Controller file, inject the Service, then create the Service layer, inject the dao layer, check the configuration files of each layer, and find that there is still no problem, so why does the file mapping fail?

Finally, I finally found the problem of type mismatch , as shown in the figure:
Here, the generic type is not added after the List, but when we declare the Address type, in fact, writing this way will not report an error, but it will cause us to map The file cannot be found!
insert image description here
Summary: The injection of data types at each layer is very important, and the rigor of code logic is very important.

————————————————
Thanks to the CSDN blogger "Yichun"
original link: https://blog.csdn.net/qq_44543508/article/details/96894891

Guess you like

Origin blog.csdn.net/Alian_auerua/article/details/130981806