Properties settings
The configuration in the Mybatis-config.xml file used in the demo project is as follows:
<span style="font-family:KaiTi_GB2312;"><?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <properties resource="com/samsung/mybatis/jdbc.properties"> <property name="username" value="chenzw"/> <property name="password" value="1258577"/> </properties> <settings> <setting name="logImpl" value="LOG4J"/> </settings> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </dataSource> </environment> </environments> <mappers> <mapper resource="com/samsung/mybatis/tiger.xml"/> </mappers></configuration></span>
The content in JDBC. properties referenced in the preceding configuration file is as follows:
<span style="font-family:KaiTi_GB2312;">driver=com.mysql.jdbc.Driverurl=jdbc:mysql://127.0.0.1:3306/testusername=chenzwpassword=7758521</span>
Loading Sequence of Properties
The order in which mybatis loads properties is as follows:
1) First, mybatis will find the properties content in the configuration file, for example, username = chenzw above and Password = 1258577 above, in parsing XML files, the relevant objects are recorded in properties in the configuration file.
2) then, mybatis will find the content pointed to by the properties node property resource. For example, in the demo above, the content pointed to by this property is JDBC. in the properties file, mybatis will parse the above content and get the content of the properties file. At this time, we will find that there is a password conflict, there are two different values of the Password attribute, here, remember that mybatis will change the password file to 7758521 Based on the found information.
3) In fact, all the parameters configured here will be passed to the relevant method for execution using the property value of a record. The called method is described as follows in the mybatis API documentation:
Sqlsessionfactoryfactory = sqlsessionfactorybuilder. Build (reader, props );
Sqlsessionfactoryfactory = sqlsessionfactorybuilder. Build (reader, environment, props );
Therefore, if a change occurs in the parameter, it is equal to the result of the test. The last step is replaced by someone else, and the previous steps have become useless.