1 Configuration Structure
- properties
- settings
- typeAliases
- typeHandlers
- objectFactory
- plugins
-
environments
- environment
- transactionManager
- dataSource
- environment
- databaseIdProvider
- mappers
2 settings
cacheEnabled
Globally enables or disables any caches configured in any mapper under this configuration.
描述:全局開啟或關(guān)閉配置文件中所有 mapper 已經(jīng)配置的緩存吉殃。
可選值:true|false
默認(rèn)值:truelazyLoadingEnabled
Globally enables or disables lazy loading. When enabled, all relations will be lazily loaded. This value can be superseded for an specific relation by using the fetchType attribute on it.
描述:全局開啟或關(guān)閉延遲加載涯保。開啟時鞋真,所有關(guān)聯(lián)對象都會延遲加載绑莺。特定關(guān)聯(lián)關(guān)系中可以通過設(shè)置 fetchType 屬性來取覆蓋該項的開關(guān)狀態(tài)带饱。
可選值:true|false
默認(rèn)值:falseaggressiveLazyLoading
When enabled, any method call will load all the lazy properties of the object. Otherwise, each property is loaded on demand (see also lazyLoadTriggerMethods).
描述:開啟或關(guān)閉屬性的延遲加載僧凰。開啟時羡儿,任何方法調(diào)用都將加載該對象的所有延遲屬性败匹。關(guān)閉時撮胧,每個屬性將按需加載(參考 lazyLoadTriggerMethods)桨踪。
可選值:true|false
默認(rèn)值:false (true in ≤3.4.1)multipleResultSetsEnabled
Allows or disallows multiple ResultSets to be returned from a single statement (compatible driver required).
描述:是否允許單個語句中返回多個結(jié)果集(需要兼容驅(qū)動)。
可選值:true|false
默認(rèn)值:trueuseColumnLabe
Uses the column label instead of the column name. Different drivers behave differently in this respect. Refer to the driver documentation, or test out both modes to determine how your driver behaves.
描述:使用列別名替代列名芹啥。不同驅(qū)動在這方面表現(xiàn)不同锻离。具體可參考驅(qū)動文檔,或者通過測試判斷這兩種模式下不同驅(qū)動的表現(xiàn)墓怀。
可選值:true|false
默認(rèn)值:trueuseGeneratedKeys
Allows JDBC support for generated keys. A compatible driver is required. This setting forces generated keys to be used if set to true, as some drivers deny compatibility but still work (e.g. Derby).
描述:是否允許 JDBC 支持主鍵自動生成汽纠。需要兼容驅(qū)動。若設(shè)置為 true傀履,則強(qiáng)制使用主鍵自動生成虱朵,盡管一些驅(qū)動不兼容也可以正常工作(如 Derby)。
可選項:true|false
默認(rèn)值:falseautoMappingBehavior
Specifies if and how MyBatis should automatically map columns to fields/properties.
NONE disables auto-mapping.
PARTIAL will only auto-map results with no nested result mappings defined inside.
FULL will auto-map result mappings of any complexity (containing nested or otherwise).
描述:指定 Mybatis 是否自動映射列到字段或?qū)傩浴?br> NONE:不允許自動映射。
PARTIAL:只自動映射沒有定義嵌套結(jié)果集映射的結(jié)果集碴犬。
FULL:自動映射任意復(fù)雜的結(jié)果集(無論是否嵌套)絮宁。
可選值:NONE, PARTIAL, FULL
默認(rèn)值:PARTIALautoMappingUnknownColumnBehavior
Specify the behavior when detects an unknown column (or unknown property type) of automatic mapping target.
NONE: Do nothing.
WARNING: Output warning log (The log level of 'org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' must be set to WARN).
FAILING: Fail mapping (Throw SqlSessionException)。
描述:指定發(fā)現(xiàn)自動映射目標(biāo)未知列(或未知屬性類型)的行為服协。
NONE:什么也不做绍昂。
WARNING:輸出警告日志( 'org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' 的日志級別要設(shè)置為 WARN)。
FAILING:映射失敵ズ伞(拋出 SqlSessionException 異常)窘游。
可選值:NONE, WARNING, FAILING
默認(rèn)值:NONEdefaultExecutorType
Configures the default executor.
SIMPLE executor does nothing special.
REUSE executor reuses prepared statements.
BATCH executor reuses statements and batches updates.
描述:配置默認(rèn)執(zhí)行器涌献。
SIMPLE:普通的執(zhí)行器贯吓。
REUSE:重復(fù)執(zhí)行預(yù)處理語句(prepared statements)。
BATCH:重復(fù)執(zhí)行語句并執(zhí)行批量更新堪簿。
可選值:SIMPLE REUSE BATCH
默認(rèn)值:SIMPLEdefaultStatementTimeout
Sets the number of seconds the driver will wait for a response from the database.
描述:設(shè)置驅(qū)動等待數(shù)據(jù)庫響應(yīng)的超時秒數(shù)棒旗。
可選值:Any positive integer //任意正整數(shù)
默認(rèn)值:Not Set (null)defaultFetchSize
Sets the driver a hint as to control fetching size for return results. This parameter value can be override by a query setting.
描述:為驅(qū)動的結(jié)果集獲取數(shù)量設(shè)置一個提示值喘批。這個參數(shù)值可以被查詢設(shè)置覆蓋。
可選值:Any positive integer //任意正整數(shù)
默認(rèn)值:Not Set (null)safeRowBoundsEnabled
Allows using RowBounds on nested statements. If allow, set the false.
描述:允許在嵌套語句中使用 RowBound铣揉。如果允許饶深,設(shè)置為 false。
可選值:true|false
默認(rèn)值:falsesafeResultHandlerEnabled
Allows using ResultHandler on nested statements. If allow, set the false.
描述:允許在嵌套語句中使用 ResultHandler逛拱。如果允許敌厘,設(shè)置為 false。
可選值:true|false
默認(rèn)值:truemapUnderscoreToCamelCase
Enables automatic mapping from classic database column names A_COLUMN to camel case classic Java property names aColumn.
描述:開啟駝峰規(guī)則命名的自動映射朽合,即從經(jīng)典數(shù)據(jù)庫列名命名 A_COLUMN 到經(jīng)典 Java 屬性命名 aColumn 的自動映射俱两。
可選值:true|false
默認(rèn)值:FalselocalCacheScope
MyBatis uses local cache to prevent circular references and speed up repeated nested queries. By default (SESSION) all queries executed during a session are cached. If localCacheScope=STATEMENT local session will be used just for statement execution, no data will be shared between two different calls to the same SqlSession.
描述:Mybatis 使用本地緩存機(jī)制(local cache)來防止循環(huán)引用和加速重復(fù)嵌套查詢。
SESSION:默認(rèn)設(shè)置曹步,一個 session 期間的所有查詢執(zhí)行都將被緩存宪彩。
STATEMENT:本地 session 僅在語句執(zhí)行時使用,且對同一個 session 的不同調(diào)用不會共享數(shù)據(jù)讲婚。
可選項:SESSION|STATEMENT
默認(rèn)值:SESSIONjdbcTypeForNull
Specifies the JDBC type for null values when no specific JDBC type was provided for the parameter. Some drivers require specifying the column JDBC type but others work with generic values like NULL, VARCHAR or OTHER.
描述:未對參數(shù)指定 JDBC 類型時尿孔,當(dāng)參數(shù)為空值時指定 JDBC 類型。某些驅(qū)動要求指定列的 JDBC 類型筹麸,某些驅(qū)動用一般類型活合,比如 NULL、VARCHAR 或 OTHER 即可物赶。
可選值:JdbcType enumeration. Most common are: NULL, VARCHAR and OTHER
默認(rèn)值:OTHERlazyLoadTriggerMethods
Specifies which Object's methods trigger a lazy load
描述:指定對象的哪些方法觸發(fā)一次延遲加載白指。
可選值:A method name list separated by commas //逗號分隔的方法名稱列表
默認(rèn)值:equals,clone,hashCode,toStringdefaultScriptingLanguage
Specifies the language used by default for dynamic SQL generation.
描述:指定動態(tài) SQL 生成的默認(rèn)語言。
可選值:A type alias or fully qualified class name.
類型別名或完全限定類名
默認(rèn)值:org.apache.ibatis.scripting.xmltags.XMLLanguageDriverdefaultEnumTypeHandler
Specifies the TypeHandler used by default for Enum. (Since: 3.4.5)
描述:指定 Enum 默認(rèn)使用的 TypeHandler(從3.4.5開始)块差。
可選值:A type alias or fully qualified class name. //類型別名或完全限定類名
默認(rèn)值:org.apache.ibatis.type.EnumTypeHandlercallSettersOnNulls
Specifies if setters or map's put method will be called when a retrieved value is null. It is useful when you rely on Map.keySet() or null value initialization. Note primitives such as (int,boolean,etc.) will not be set to null.
描述:指定當(dāng)結(jié)果集中值為空時是否調(diào)用映射對象的 setter 方法或 map 的 put 方法侵续。如果你依賴于 Map.keySet() 或者在 null 值初始化時倔丈,該設(shè)置有用憨闰。注意状蜗,基本類型比如 int 、boolean 等不能被設(shè)置為 null鹉动。
可選值:true | false
默認(rèn)值:falsereturnInstanceForEmptyRow
MyBatis, by default, returns null when all the columns of a returned row are NULL. When this setting is enabled, MyBatis returns an empty instance instead. Note that it is also applied to nested results (i.e. collectioin and association). Since: 3.4.2
描述:當(dāng)返回行的所有列都是 null 時轧坎,Mybatis 默認(rèn)返回 null 。當(dāng)該設(shè)置被開啟時泽示,Mybatis 會返回一個空實例缸血。注意這將同樣適用于嵌套結(jié)果集(如 collection 和 association)。從 3.4.2 開始械筛。
可選值:true | false
默認(rèn)值:falselogPrefix
Specifies the prefix string that MyBatis will add to the logger names.
描述:指定 Mybatis 添加到日志名稱的前綴捎泻。
可選值:Any String
默認(rèn)值:Not setlogImpl
Specifies which logging implementation MyBatis should use. If this setting is not present logging implementation will be autodiscovered.
描述:指定 Mybatis 使用的日志工具。如果此項未設(shè)置埋哟,將會自動查找日志工具笆豁。
可選值:SLF4J | LOG4J | LOG4J2 | JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING
默認(rèn)值:Not setproxyFactory
Specifies the proxy tool that MyBatis will use for creating lazy loading capable objects.
描述:指定 Mybatis 創(chuàng)建具有懶加載能力的對象的代理工具。
可選值:CGLIB | JAVASSIST
默認(rèn)值:JAVASSIST (MyBatis 3.3 or above)vfsImpl
Specifies VFS implementations
描述:指定 VFS 的具體實現(xiàn)赤赊。
可選值:Fully qualified class names of custom VFS implementation separated by commas. //逗號分隔的自定義 VFS 具體實現(xiàn)的完全限定類名闯狱。
默認(rèn)值:Not setuseActualParamName
Allow referencing statement parameters by their actual names declared in the method signature. To use this feature, your project must be compiled in Java 8 with -parameters option. (Since: 3.4.1)
描述:允許將方法簽名中定義的真實名稱作為語句參數(shù)名稱。為了使用這一特性抛计,你的項目必須采用 java 8 編譯哄孤,且必須加上 -parameters 選項。(從 3.4.1 開始)
可選值:true | false
默認(rèn)值:trueconfigurationFactory
Specifies the class that provides an instance of Configuration. The returned Configuration instance is used to load lazy properties of deserialized objects. This class must have a method with a signature static Configuration getConfiguration(). (Since: 3.2.3)
描述:指定提供 Configuration 實例的類吹截。返回的 Configuration 實例用來加載被反序列化對象的懶加載屬性瘦陈。這個類必須有一個 static Configuration getConfiguration() 簽名方法。(從 3.2.3 開始)
可選值:A type alias or fully qualified class name. //類型別名或完全限定類名
默認(rèn)值:Not set
配置示例如下:
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="multipleResultSetsEnabled" value="true"/>
<setting name="useColumnLabel" value="true"/>
<setting name="useGeneratedKeys" value="false"/>
<setting name="autoMappingBehavior" value="PARTIAL"/>
<setting name="autoMappingUnknownColumnBehavior" value="WARNING"/>
<setting name="defaultExecutorType" value="SIMPLE"/>
<setting name="defaultStatementTimeout" value="25"/>
<setting name="defaultFetchSize" value="100"/>
<setting name="safeRowBoundsEnabled" value="false"/>
<setting name="mapUnderscoreToCamelCase" value="false"/>
<setting name="localCacheScope" value="SESSION"/>
<setting name="jdbcTypeForNull" value="OTHER"/>
<setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
</settings>
最后
說明:MyBatis 官網(wǎng)提供了簡體中文的翻譯波俄,但個人覺得較為生硬晨逝,甚至有些地方邏輯不通,于是自己一個個重新敲著翻譯的(都不知道哪里來的自信...)弟断,有些地方同官網(wǎng)翻譯有出入咏花,有些倔強(qiáng)地保留了自己的,有的實在別扭則保留了官網(wǎng)的阀趴,這些都會在實踐中一一更正昏翰。鑒于個人英文能力有限,文章中保留了官方文檔原英文介紹(個別地方加以調(diào)整修剪)刘急,希望有緣看到這里的朋友們能夠有自己的理解棚菊,不會被我可能錯誤或不合理的翻譯帶跑偏(〃'▽'〃),歡迎指正叔汁!
當(dāng)前版本:mybatis-3.5.0
官網(wǎng)文檔:MyBatis
官網(wǎng)翻譯:MyBatis 簡體中文
項目實踐:MyBatis Learn