Mybatis basic entry 5 core configuration file

Source: Internet
Author: User
Mybatis basic entry 5 core configuration file

Description:

In the previous chapter, I learned how to use mybatis, but I have not described many configuration files in detail.

Here we first describe a core configuration file in the project: The mybatis-config.xml file.

Reference: http://www.mybatis.org/mybatis-3/

1 <? XML version = "1.0" encoding = "UTF-8"?> 2 <! Doctype configuration 3 Public "-// mybatis.org//dtd config 3.0 // en" 4 "http://mybatis.org/dtd/mybatis-3-config.dtd"> 5 6 <! -- Configuration --> 7 <configuration> 8 9 <! -- Can be configured in the Java property configuration file --> 10 <Properties> </Properties> 11 12 <! -- Modify the behavior of mybatis at runtime --> 13 <Settings> </Settings> 14 15 <! -- An alias (abbreviation) for Java commands --> 16 <typealiases> </typealiases> 17 18 <! -- Type Processor --> 19 <typehandlers> </typehandlers> 20 21 <! -- Object factory --> 22 <objectfactory type = ""> </objectfactory> 23 24 <! -- Plug-in --> 25 <plugins> </plugins> 26 27 <! -- Environment --> 28 <environments default = ""> 29 30 <! -- Environment variable --> 31 <environment id = ""> 32 33 <! -- Configure the Transaction Manager --> 34 <transactionmanager type = ""> </transactionmanager> 35 <! -- Configure the data source --> 36 <datasource type = ""> </datasource> 37 38 </environment> 39 40 </environments> 41 42 <! -- --> 43 <mappers> </mappers> 44 45 </configuration>

Note:

The labels in the preceding configuration file must be written in this order. Otherwise, mybatis will report an error when parsing the file.

 

<Properties> </Properties>

>>> Two methods for configuring the properties Element

1. implement dynamic configuration by specifying the external method (database. properties)

> Configure the resource attribute of Properties

    

This method is used in the previous chapter. External import is performed at location 1. Then use it at location 2.

  

2. Configure XML directly for dynamic configuration

> Name and value of Properties

 

Properties problems:

1. If both methods are used at the same time, which method takes precedence?

> Configure resource settings for properties

> Configure the name and value of the property.

      

Test method:

1. Modify the Value Attribute Value of the tag property and run the query test method.

2. Restore the value property value of the modified property tag, modify the data in the database. properties file, and run the query test method. The program throws an exception error.

    Conclusion: the priority of the resource attribute value is higher than that configured for the property subnode.

 

<Settings> </Settings>

1. Used to modify the behavior of mybatis during runtime

2. Set global configuration attributes of mybatis.

For example, configure a delayed Loading

  

 

<Typealiases> </typealiases>

1. Used to modify the type alias

2. Only the xml configuration is associated. the lengthy Java name is abbreviated. For usage, see "mybatis basics" 3 "SELECT query set" SELECT query method 3.

 

<Environments> </environments>

1. Configure multiple runtime environments for mybatis and map the SQL statements to multiple different databases.

2. subelement node: environment, but one of them must be specified as the default running environment (specified through default)

<Transactionmanager> </transactionmanager> Transaction Manager

<Transactionmanager type = "[JDBC | managed]"/>

JDBC | managed

 

<Datasource> </datasource>

>>> The datasource element uses the basic JDBC data source interface to configure resources of the JDBC connection object.

>>> There are three built-in data source types
<Datasource type = "[unpooled | pooled | JNDI]"/>

<Mappers> </mappers>

1. er, which defines SQL ing statements

2. The Mapper ing file must be referenced in the configuration.

......

  

If you have any questions, please correct them !!!

If you have reproduced, please mark the Source: https://www.cnblogs.com/Charles-Yuan/p/9862302.html

 

References: http://www.mybatis.org/mybatis-3/zh/configuration.html

 

Mybatis basic entry 5 core configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.