Mybatis-config.xml Example

Source: Internet
Author: User
Tags xml 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>

<!-- parameter Settings --

<settings>  

<!--This configuration enables the global mapper to enable or disable the cache--

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

<!--enable or disable lazy loading globally. When disabled, all associated objects are loaded instantly--

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

<!--when enabled, an object with lazy loading properties will fully load any property when called. Otherwise, each property will be loaded as needed-

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

<!--allow or disallow multiple result sets to be returned from a single statement (requires a suitable driver)--

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

<!--use column labels instead of column names. Different drivers are different in this convenient performance. Refer to the driver documentation or fully test two methods to determine the drive used--

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

<!--allows JDBC to support generated keys. A suitable driver is required. If set to true then this setting forces the generated keys to be used, although some drivers are refused compatible but still valid (such as Derby)--

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

<!--Specify how MyBatis automatically maps columns to fields/properties. The partial only automatically maps simple, no nested results. Full will automatically map arbitrarily complex results (nested or otherwise)--

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

<!--when an unknown column (or unknown attribute) is detected, there is no prompt by default, which is inconvenient at the time of testing and is not easy to find errors.

None: Do not do any processing (default value)

WARNING: Warning Log form details

Failing: Mapping failed, throwing exceptions and details

-

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

<!--Configure the default executor. Simple actuators are nothing special. The reuse executor uses the preprocessing statement. Batch Executor uses statements and bulk updates--

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

<!--set the time-out time, which determines how long it takes to wait for a database response.

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

<!--set the number of query return values, which can be overridden by the query value

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

<!--allows you to use paging in nested statements--

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

<!--whether to turn on the automatic Hump naming convention (Camel case) mapping, which is a similar mapping from the classic database column name A_column to the classic Java attribute name Acolumn. -

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

<!--MyBatis uses the local cache mechanism to prevent circular references (circular references) and to accelerate duplicate nested queries. The default value is session, in which case all queries executed in one session are cached. If the setting value is STATEMENT, the local session is used only on statement execution, and different calls to the same sqlsession will not share the data. -

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

<!--Specifies the JDBC type for null values when no specific JDBC type is supplied for the parameter. Some drivers need to specify the JDBC type of the column, most of which are normal types, such as NULL, VARCHAR

Other. -

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

<!--specifies which object's method triggers a lazy load. -

<setting name= "Lazyloadtriggermethods" value= "equals,clone,hashcode,tostring"/>

</settings>

<!-- alias definition --

<typeAliases>  

<typealias alias= "Pageaccessurl" type= "Com.lgm.mybatis.model.PageAccessURL"/>

</typeAliases>

<!-- Custom Type Processor --

<typeHandlers>

<!--<typehandler handler= "Com.xhm.util.BooleanTypeHandlder"/>--

<!--scan the custom type processor under the entire package--

<package name= "Com.xhm.util"/>

</typeHandlers>

<!--plugins plug-in paging blocker--

<plugins>

<plugin interceptor= "Com.xhm.util.PageInterceptor" ></plugin>

</plugins>

<!-- Configure the environment environment --

<environments default= "Development">

<!--environment Configuration 1, each sqlsessionfactory one environment--

<environment id= "Development1" >

<!-- transaction configuration type= jdbc, MANAGED 1.JDBC: This configuration simply uses the JDBC commit and rollback settings directly. It relies on the connections obtained from the data source to manage the scope of the transaction.

2.MANAGED: This configuration hardly does anything. It never commits or rolls back a connection. Instead, it allows the container to manage the entire lifecycle of a transaction (such as the context of a spring or JEE application server). By default, it closes the connection. However some containers do not want this, so if you need to stop it from the connection, set the CloseConnection property to false--

<transactionmanager type= "JDBC"/>

<!--<transactionmanager type= "MANAGED" >

<property name= "CloseConnection" value= "false"/>

</transactionManager>

<!-- Data source type: type = unpooled, pooled, JNDI1.UNPOOLED: The implementation of this data source is to simply open and close the connection each time it is requested. It's a little bit slow, which is a good choice for simple applications because it doesn't need to be available in a timely connection.

Different databases for this performance is not the same, so for some database configuration data source is not important, this configuration is idle 2.POOLED: This is the JDBC Connection object data source connection pool implementation, to avoid the creation of new connection instances when necessary initial connection and authentication time.

This is a popular way for the current Web application to respond quickly to requests. 3.JNDI: This data source is implemented to use containers such as spring or application server, where the container can configure the data source centrally or externally, and then place a reference to a JNDI context--

<datasource type= "unpooled" >

<property name= "Driver" value= "Com.mysql.jdbc.Driver"/>

<property name= "url" value= "Jdbc:mysql://localhost:3306/xhm"/>

<property name= "username" value= "root"/>

<property name= "Password" value= "root"/>

<!--default connection transaction ISOLATION level <property name= "Defaulttransactionisolationlevel" value= ""

/>--

</dataSource>

</environment>

<!--Environment Configuration 2--

<environment id= "Development2" >

<transactionmanager type= "JDBC"/>

<datasource type= "Pooled" >

<property name= "Driver" value= "Com.mysql.jdbc.Driver"/>

<property name= "url" value= "Jdbc:mysql://localhost:3306/xhm"/>

<property name= "username" value= "root"/>

<property name= "Password" value= "root"/>

<!--the number of connections that exist at any time (that is, in use)--

<property name= "Poolmaximumactiveconnections" value= "ten"/>

<!--idle connections available at any time--

<property name= "Poolmaximumidleconnections" value= "5"/>

<!--the time that the connection in the pool was checked before it was forced to return-

<property name= "Poolmaximumcheckouttime" value= "20000"/>

<!--This is a low-level setting that gives the connection Pool A print log status opportunity, and a retry to get the connection, which often takes a long time (to avoid silent failure when the connection pool is not configured)-

<property name= "pooltimetowait" value= "20000"/>

<!--a reconnaissance query sent to the data to verify that the connection is working properly and is ready to accept the request. -

<property name= "Poolpingquery" value= "NO PING QUERY SET"/>

<!--This is to turn reconnaissance queries on or off. If you turn it on, you must set the Poolpingquery property with a valid SQL statement (preferably very fast)--

<property name= "poolpingenabled" value= "false"/>

<!--This is used to configure poolpingquery multiple times to be used once. This can be set to match the standard database connection timeout time to avoid unnecessary detection--

<property name= "poolpingconnectionsnotusedfor" value= "0"/>

</dataSource>

</environment>

<!--Environment Configuration 3--

<environment id= "Development3" >

<transactionmanager type= "JDBC"/>

<datasource type= "JNDI" >

<property name= "data_source" value= "Java:comp/env/jndi/mybatis"/>

<property name= "env.encoding" value= "UTF8"/>

<!--<property name= "Initial_context" value= ""/> <property name= "env.encoding"

Value= "UTF8"/>--

</dataSource>

</environment>

</environments>

<!-- mapping file, mapper configuration file--  

<mappers>

<!--map directly to the appropriate mapper file--

<mapper resource= "Com/xhm/mapper/usermapper.xml"/>

<!--scan the package path for all xxmapper.xml files--

<package name= "Com.xhm.mapper"/>

</mappers>

</configuration>

Mybatis-config.xml Example

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.