Config. In mybatis Detailed parsing of XML configuration file
After the previous articles, I think the understanding of the main topic of mybatis is enough, but I think the use of mybatis will still be a little vague. Personally, I think to master the mybatis framework, I mainly need to understand three documents. The first is mybatis comfig XML file, and * * mapper XML and mapper class defined by us. If we understand these three things and have the foundation of SQL and Java, it will be much simpler to use XML based methods or Java based configuration methods.
Without much nonsense, let's understand the first important file: mybatis config XML file.
First, let's take a look at a blank and complete mybatis config XML file (this name can be operated freely. You must remember that this is the mybatis configuration file)
You can directly create a blank XML file, then go to the official website to copy a header file and paste it in
The above is the basic mybatis config XML file, we need to add the configuration we need in development. Here is a basic configuration file added. Through this:
From the above content, we can see the following labels, but what do these mean?
< configuration >: the information declared in the tag is configuration information < typealiases >: the information declared in the tag is aliases < typealias >: declare the objects to use aliases (full path) if you use Java annotation, you can use @ alias annotation to declare < environments >: declare the environment variables in the tag, default represents the default environment variables, and an environment represents a JDBC connection database. If there are many databases, we need to use different environment variables < environment >: declare environment variables < transactionmanager >: declare transaction management Its types include JDBC (JDBC based transaction) and managed (Managed Transaction) < datasource >: declare data sources. The types of data sources include nopooled, pooled, and jidn. If the amount of data is small, onpooled is used. Generally, pooled is used in testing and development processes. Jidn < property >: some properties of JDBC connection < mappers >: declare mapper classes defined by us, or associate < mapper >: declare mapper paths path
All the above mentioned are the basic tags to be used by mybatis. You must master them. You may not understand the use of the above environments and how to obtain an environment. Let's take a look at an example:
The above defaultsqlsessionfactory should be declared by itself (note)
So what other labels besides the ones above? Here's a look at other commonly used tags
< Settings >: Declaration of some global variables
< Properties >: declare the key and value of the property file, but if used The properties file will be overwritten.
< typehandlers >: to customize our incoming parameter type processor, we need to extend basetypehandler < customize the type of response >
Finally, let's take a look at the default setting configuration of mybatis:
summary
The above is the config. In mybatis introduced by Xiaobian The XML configuration file is parsed in detail. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!