美文网首页
Mybatis 文档篇 2.2:Configuration 之

Mybatis 文档篇 2.2:Configuration 之

作者: 兆雪儿 | 来源:发表于2019-03-19 19:47 被阅读0次

1 Configuration Structure

2 settings

  • cacheEnabled
    Globally enables or disables any caches configured in any mapper under this configuration.
    描述:全局开启或关闭配置文件中所有 mapper 已经配置的缓存。
    可选值:true|false
    默认值:true

  • lazyLoadingEnabled
    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.
    描述:全局开启或关闭延迟加载。开启时,所有关联对象都会延迟加载。特定关联关系中可以通过设置 fetchType 属性来取覆盖该项的开关状态。
    可选值:true|false
    默认值:false

  • aggressiveLazyLoading
    When enabled, any method call will load all the lazy properties of the object. Otherwise, each property is loaded on demand (see also lazyLoadTriggerMethods).
    描述:开启或关闭属性的延迟加载。开启时,任何方法调用都将加载该对象的所有延迟属性。关闭时,每个属性将按需加载(参考 lazyLoadTriggerMethods)。
    可选值:true|false
    默认值:false (true in ≤3.4.1)

  • multipleResultSetsEnabled
    Allows or disallows multiple ResultSets to be returned from a single statement (compatible driver required).
    描述:是否允许单个语句中返回多个结果集(需要兼容驱动)。
    可选值:true|false
    默认值:true

  • useColumnLabe
    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.
    描述:使用列别名替代列名。不同驱动在这方面表现不同。具体可参考驱动文档,或者通过测试判断这两种模式下不同驱动的表现。
    可选值:true|false
    默认值:true

  • useGeneratedKeys
    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 支持主键自动生成。需要兼容驱动。若设置为 true,则强制使用主键自动生成,尽管一些驱动不兼容也可以正常工作(如 Derby)。
    可选项:true|false
    默认值:false

  • autoMappingBehavior
    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 是否自动映射列到字段或属性。
    NONE:不允许自动映射。
    PARTIAL:只自动映射没有定义嵌套结果集映射的结果集。
    FULL:自动映射任意复杂的结果集(无论是否嵌套)。
    可选值:NONE, PARTIAL, FULL
    默认值:PARTIAL

  • autoMappingUnknownColumnBehavior
    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)。
    描述:指定发现自动映射目标未知列(或未知属性类型)的行为。
    NONE:什么也不做。
    WARNING:输出警告日志( 'org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' 的日志级别要设置为 WARN)。
    FAILING:映射失败(抛出 SqlSessionException 异常)。
    可选值:NONE, WARNING, FAILING
    默认值:NONE

  • defaultExecutorType
    Configures the default executor.
    SIMPLE executor does nothing special.
    REUSE executor reuses prepared statements.
    BATCH executor reuses statements and batches updates.
    描述:配置默认执行器。
    SIMPLE:普通的执行器。
    REUSE:重复执行预处理语句(prepared statements)。
    BATCH:重复执行语句并执行批量更新。
    可选值:SIMPLE REUSE BATCH
    默认值:SIMPLE

  • defaultStatementTimeout
    Sets the number of seconds the driver will wait for a response from the database.
    描述:设置驱动等待数据库响应的超时秒数。
    可选值:Any positive integer //任意正整数
    默认值: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.
    描述:为驱动的结果集获取数量设置一个提示值。这个参数值可以被查询设置覆盖。
    可选值:Any positive integer //任意正整数
    默认值:Not Set (null)

  • safeRowBoundsEnabled
    Allows using RowBounds on nested statements. If allow, set the false.
    描述:允许在嵌套语句中使用 RowBound。如果允许,设置为 false。
    可选值:true|false
    默认值:false

  • safeResultHandlerEnabled
    Allows using ResultHandler on nested statements. If allow, set the false.
    描述:允许在嵌套语句中使用 ResultHandler。如果允许,设置为 false。
    可选值:true|false
    默认值:true

  • mapUnderscoreToCamelCase
    Enables automatic mapping from classic database column names A_COLUMN to camel case classic Java property names aColumn.
    描述:开启驼峰规则命名的自动映射,即从经典数据库列名命名 A_COLUMN 到经典 Java 属性命名 aColumn 的自动映射。
    可选值:true|false
    默认值:False

  • localCacheScope
    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 使用本地缓存机制(local cache)来防止循环引用和加速重复嵌套查询。
    SESSION:默认设置,一个 session 期间的所有查询执行都将被缓存。
    STATEMENT:本地 session 仅在语句执行时使用,且对同一个 session 的不同调用不会共享数据。
    可选项:SESSION|STATEMENT
    默认值:SESSION

  • jdbcTypeForNull
    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.
    描述:未对参数指定 JDBC 类型时,当参数为空值时指定 JDBC 类型。某些驱动要求指定列的 JDBC 类型,某些驱动用一般类型,比如 NULL、VARCHAR 或 OTHER 即可。
    可选值:JdbcType enumeration. Most common are: NULL, VARCHAR and OTHER
    默认值:OTHER

  • lazyLoadTriggerMethods
    Specifies which Object's methods trigger a lazy load
    描述:指定对象的哪些方法触发一次延迟加载。
    可选值:A method name list separated by commas //逗号分隔的方法名称列表
    默认值:equals,clone,hashCode,toString

  • defaultScriptingLanguage
    Specifies the language used by default for dynamic SQL generation.
    描述:指定动态 SQL 生成的默认语言。
    可选值:A type alias or fully qualified class name.
    类型别名或完全限定类名
    默认值:org.apache.ibatis.scripting.xmltags.XMLLanguageDriver

  • defaultEnumTypeHandler
    Specifies the TypeHandler used by default for Enum. (Since: 3.4.5)
    描述:指定 Enum 默认使用的 TypeHandler(从3.4.5开始)。
    可选值:A type alias or fully qualified class name. //类型别名或完全限定类名
    默认值:org.apache.ibatis.type.EnumTypeHandler

  • callSettersOnNulls
    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.
    描述:指定当结果集中值为空时是否调用映射对象的 setter 方法或 map 的 put 方法。如果你依赖于 Map.keySet() 或者在 null 值初始化时,该设置有用。注意,基本类型比如 int 、boolean 等不能被设置为 null。
    可选值:true | false
    默认值:false

  • returnInstanceForEmptyRow
    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
    描述:当返回行的所有列都是 null 时,Mybatis 默认返回 null 。当该设置被开启时,Mybatis 会返回一个空实例。注意这将同样适用于嵌套结果集(如 collection 和 association)。从 3.4.2 开始。
    可选值:true | false
    默认值:false

  • logPrefix
    Specifies the prefix string that MyBatis will add to the logger names.
    描述:指定 Mybatis 添加到日志名称的前缀。
    可选值:Any String
    默认值:Not set

  • logImpl
    Specifies which logging implementation MyBatis should use. If this setting is not present logging implementation will be autodiscovered.
    描述:指定 Mybatis 使用的日志工具。如果此项未设置,将会自动查找日志工具。
    可选值:SLF4J | LOG4J | LOG4J2 | JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING
    默认值:Not set

  • proxyFactory
    Specifies the proxy tool that MyBatis will use for creating lazy loading capable objects.
    描述:指定 Mybatis 创建具有懒加载能力的对象的代理工具。
    可选值:CGLIB | JAVASSIST
    默认值:JAVASSIST (MyBatis 3.3 or above)

  • vfsImpl
    Specifies VFS implementations
    描述:指定 VFS 的具体实现。
    可选值:Fully qualified class names of custom VFS implementation separated by commas. //逗号分隔的自定义 VFS 具体实现的完全限定类名。
    默认值:Not set

  • useActualParamName
    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)
    描述:允许将方法签名中定义的真实名称作为语句参数名称。为了使用这一特性,你的项目必须采用 java 8 编译,且必须加上 -parameters 选项。(从 3.4.1 开始)
    可选值:true | false
    默认值:true

  • configurationFactory
    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. //类型别名或完全限定类名
    默认值: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 官网提供了简体中文的翻译,但个人觉得较为生硬,甚至有些地方逻辑不通,于是自己一个个重新敲着翻译的(都不知道哪里来的自信...),有些地方同官网翻译有出入,有些倔强地保留了自己的,有的实在别扭则保留了官网的,这些都会在实践中一一更正。鉴于个人英文能力有限,文章中保留了官方文档原英文介绍(个别地方加以调整修剪),希望有缘看到这里的朋友们能够有自己的理解,不会被我可能错误或不合理的翻译带跑偏(〃'▽'〃),欢迎指正!

当前版本:mybatis-3.5.0
官网文档:MyBatis
官网翻译:MyBatis 简体中文
项目实践:MyBatis Learn

相关文章

网友评论

      本文标题:Mybatis 文档篇 2.2:Configuration 之

      本文链接:https://www.haomeiwen.com/subject/dcknmqtx.html