2. MyBatis Series: A detailed description of the global configuration file

Source: Internet
Author: User

MyBatis Global Mapping configuration file

The top-level structure of the MyBatis configuration document is as follows:

Configuration configurations

    • Properties Property
    • Settings settings
    • Typealiases type naming
    • Typehandlers Type processor
    • Objectfactory Object Factory
    • Plugins Plug-in
    • Environments Environment
    • Databaseidprovider Database Vendor Identification
      • Environment Environment variables
        • TransactionManager transaction Manager
        • DataSource Data source
    • Mappers Mapper
Configuration file Example
<?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>    <!--there are 3 places where you can define attribute values, which are read according to a preference level (1>2>3), overwriting a property with the same name with a lower priority. 1. Sqlsessionfactorybuilder.build (reader, props);         The property that is transferred in the method.         2. Attributes defined within the properties element. 3. Resource read properties in the properties file.  -    <PropertiesResource= "Db.properties">        < Propertyname= "UserName1"value= "Dev_user" />    </Properties>    <!--mybatis Internal parameter settings will change the behavior of the MyBatis runtime. Here are a few examples of commonly used parameters.  -    <Settings>        <!--enabled cache is set, default is True -        <settingname= "cacheenabled"value= "true" />        <!--enabled deferred load is set, default is False -        <settingname= "lazyloadingenabled"value= "true" />        <!--set the Enable single SQL statement to multiple return sets, which defaults to true. -        <settingname= "multipleresultsetsenabled"value= "true" />    </Settings>    <!--used to define a Java type as a short alias that reduces the redundancy of the fully qualified name of the class. For example, the JDBC used in the environment tag, pooled has a built-in defined alias.  -    <typealiases>        <!--defines a single Java type and defines an alias for it. -        <Typealiasalias= "User"type= "Cn.xleos.mybatis.po.User" />        <!--Specify all Java types under a package and use the first lowercase of the class name as their alias. If there are multiple packages, you only need to define multiple package labels. -        <!--<package name= "Cn.xleos.mybatis.po"/> -    </typealiases>    <!--database field value to entity attribute data type conversion Processor Definition -    <typehandlers>        <!--This defines a type converter that can be serializable type and JSON type.              This converter is called by default when the field JDBC type is CLOB and the entity attribute type is map,mybatis to turn data to an entity.         Other converters can also be specified in the Mapper configuration file.  -        <TypehandlerHandler= "Cn.xleos.mybatis.typehandlers.JsonTypeHandler"Javatype= "Java.util.Map"Jdbctype= "CLOB" />    </typehandlers>        <!--used to intercept calls when a mapping statement is executed. -    <Plugins>        <!--This is used for physical paging of the database when the query method is executed. -        <pluginInterceptor= "Cn.xleos.framework.mybatis.paginator.OffsetLimitInterceptor">            <!--Offsetlimitinterceptor property settings that inform the database support used by the paging plug-in.  -            < Propertyname= "dialect"value= "Cn.xleos.framework.mybatis.paginator.dialect.MSSQL2005Dialect" />        </plugin>    </Plugins>    <!--   -    <Environmentsdefault= "Development">        <EnvironmentID= "Development">            <!--Configure the type of transaction manager used by the project, and JDBC is an alias for Jdbctransactionfactory.class -            <TransactionManagertype= "JDBC" />            <!--Configure the data source type, pooled to Pooleddatasourcefactory.class alias -            <DataSourcetype= "Pooled">                < Propertyname= "Driver"value= "${jdbc.driver}" />                < Propertyname= "url"value= "${jdbc.url}" />                < Propertyname= "username"value= "${jdbc.username}" />                < Propertyname= "Password"value= "${jdbc.password}" />            </DataSource>        </Environment>    </Environments>    <!--support for multiple databases, based on the DatabaseID property of the Mapper map statement.     Db_vendor is the alias of the Org.apache.ibatis.mapping.VendorDatabaseIdProvider built into the mybatis.  -    <Databaseidprovidertype= "Db_vendor">        <!--The following property.name are the names obtained by Databasemetadata#getdatabaseproductname ().         Property.Value is a short-defined alias that will be used to match the DatabaseId property of the Mapper mapping statement.  -        < Propertyname= "SQL Server"value= "SQL Server" />        < Propertyname= "DB2"value= "DB2" />        < Propertyname= "Oracle"value= "Oracle" />    </Databaseidprovider>        <!--tell MyBatis where to go to query the mapping file. -    <mappers>        <!--The Mapper mapping file path for the user used by the configuration project -        <MapperResource= "Mapper/user.xml" />    </mappers>    </Configuration>

2, MyBatis Series: A detailed description of the global 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.