How to solve the pit of configuring sub-tag package in Mybatis mapper tags
This article mainly introduces how to solve the Mybatis mapper tag configuration sub-tag package pit, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.
The pit where the subtag package is configured in the mapper tag
First of all, the .java file under the java directory and the .xml file under resources must be in the same directory, but when you create a directory in resource, don't create a com.mapper folder just like you created a package in a java file. Instead of creating two folders called com-mapper, you create a folder called com.mapper!
This will cause the location of the .java file to be different from that of the .xml file, which has fooled me for an hour. I hope you will pay attention to this.
Introduction of mappers tags in Mybatis
MyBatis is a framework based on sql mapping configuration. Sql statements are written in the Mapper configuration file. After building the SqlSession class, you need to read the sql configuration in the Mapper configuration file.
The mappers tag is used to configure the path of the sql mapping profile that needs to be loaded.
Configuration mode
There are many mapper tags under the mappers tag, and each mapper tag is configured with a path to a separate mapping profile, which can be configured in the following ways
1. The package where the interface resides
Package tag, which specifies the package name where the mapper interface is located through the name attribute
At this point, the corresponding mapping file must be in the same path as the interface and have the same name.
two。 Relative path configuration
Mapper tag, which introduces the relative resource of the classpath path through the resource attribute
3. Class registration introduction
Mapper tag, which specifies the mapper interface name through the class attribute
At this point, the corresponding mapping file must be in the same path as the interface and have the same name.
4. Introduction using URL absolute path (no)
Mapper tag to introduce network resources or local disk resources through url
Thank you for reading this article carefully. I hope the article "how to solve the problem of configuring sub-tag package in Mybatis mapper tags" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!