[Mybatis configuration file overview]

1. The configuration content and order of SqlMapConfig.xml are as follows, and the order cannot be disordered.

<?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">  

<!-- The root element of the configuration file -->  

<configuration>  

    <!-- Properties: Define configuration externalization -->  

    <properties></properties>  

    <!-- Settings: define some global settings for mybatis -->  

    <settings>  

       <!-- Specific parameter name and parameter value-->  

       <setting name="" value=""/>   

    </settings>  

   <!-- type name: define aliases for some classes -->  

    <typeAliases></typeAliases>  

    <!-- Type processor: defines the conversion relationship between Java types and data types in the database -->  

    <typeHandlers></typeHandlers>  

    <!-- Object Factory -->  

    <objectFactory type=""></objectFactory>  

    <!-- Plug-in: mybatis plug-in, the plug-in can modify the internal running rules of mybatis -->  

    <plugins>  

       <plugin interceptor=""></plugin>  

    </plugins>  

   <!-- Environment: configure the environment of mybatis -->  

    <environments default="">  

       <!-- Environment variables: You can configure multiple environment variables. For example, when using multiple data sources, you need to configure multiple environment variables-->  

       <environment id="">  

          <!-- Transaction Manager -->  

          <transactionManager type=""></transactionManager>  

          <!-- datasource-->  

          <dataSource type=""></dataSource>  

       </environment>   

    </environments>  

    <!-- Database vendor ID-->  

    <databaseIdProvider type=""></databaseIdProvider>  

    <!-- Mapper: specify the mapping file or mapping class -->  

    <mappers></mappers>  

</configuration>  

 

 

2. Properties file configuration

Option One:

<!--Introduce external properties file--> < properties resource = "db.properties" > </ properties >

Option II:

<properties>
     <property name="driver" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/test" />
    <property name="username" value="root" />
     <property name="password" value="root" />
 </properties>
Configure what needs to be connected to the database driver in the child element of the properties element

Then set it dynamically in the dataSource element of the environment element
<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>



 Option 3: Program parameter transfer



 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326862255&siteId=291194637