5、Configuration构建之setting节点介绍
来源:互联网 发布:电影资源知乎 编辑:程序博客网 时间:2024/06/05 15:14
settings
下表描述了设置中各项的意图、默认值等。
setting元素对应的类
public class Configuration { //setting的配置 /** * 1.该配置影响的所有映射器中配置的缓存的全局开关。 */ protected boolean cacheEnabled = true; /** * 2.延迟加载的全局开关。当开启时,所有关联对象都会延迟加载。 特定关联关系中可通过设置fetchType属性来覆盖该项的开关状态。 */ protected boolean lazyLoadingEnabled = false; /** * 3.当开启时,任何方法的调用都会加载该对象的所有属性。否则,每个属性会按需加载。默认false */ protected boolean aggressiveLazyLoading; /** * 4. 是否允许单一语句返回多结果集(需要兼容驱动)。 */ protected boolean multipleResultSetsEnabled = true; /** * 5.使用列标签代替列名。不同的驱动在这方面会有不同的表现 */ protected boolean useColumnLabel = true; /** * 6.允许 JDBC 支持自动生成主键,需要驱动兼容 */ protected boolean useGeneratedKeys; /** * 7.指定 MyBatis 应如何自动映射列到字段或属性。 * NONE 表示取消自动映射; * PARTIAL 只会自动映射没有定义嵌套结果集映射的结果集。(意思就是映射文件中,对于resultMap标签,如果没有显式定义result标签, * mybatis不会帮你把结果映射到model(pojo)上.除了id属性有具体值外,其余都没有) * FULL 会自动映射任意复杂的结果集(无论是否嵌套)。 */ protected AutoMappingBehavior autoMappingBehavior = AutoMappingBehavior.PARTIAL; /** * 8.指定发现自动映射目标未知列(或者未知属性类型)的行为。 * NONE: 不做任何反应 * WARNING: 输出提醒日志 ('org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' 的日志等级必须设置为 WARN) * FAILING: 映射失败 (抛出 SqlSessionException) */ protected AutoMappingUnknownColumnBehavior autoMappingUnknownColumnBehavior = AutoMappingUnknownColumnBehavior.NONE; /** * 9. 配置默认的执行器。 * SIMPLE 就是普通的执行器;REUSE 执行器会重用预处理语句(prepared statements); * BATCH 执行器将重用语句并执行批量更新。 */ protected ExecutorType defaultExecutorType = ExecutorType.SIMPLE; /** * 10.设置超时时间,它决定驱动等待数据库响应的秒数。 */ protected Integer defaultStatementTimeout; /** * 11.果集获取数量(fetchSize)设置一个提示值,此参数只可以在查询设置中被覆盖。 */ protected Integer defaultFetchSize; /** * 12. 允许在嵌套语句中使用分页(RowBounds)。 If allow, set the false. */ protected boolean safeRowBoundsEnabled; /** * 13.允许在嵌套语句中使用分页(ResultHandler)。 If allow, set the false. */ protected boolean safeResultHandlerEnabled = true; /** * 14.是否开启自动驼峰命名规则(camel case)映射 */ protected boolean mapUnderscoreToCamelCase; /** * 15. MyBatis 利用本地缓存机制(Local Cache)防止循环引用(circular references)和加速重复嵌套查询。 * 默认值为 SESSION,这种情况下会缓存一个会话中执行的所有查询。 * 若设置值为 STATEMENT,本地会话仅用在语句执行上,对相同 SqlSession 的不同调用将不会共享数据。 */ protected LocalCacheScope localCacheScope = LocalCacheScope.SESSION; /** * 16.当没有为参数提供特定的 JDBC 类型时,为空值指定 JDBC 类型 */ protected JdbcType jdbcTypeForNull = JdbcType.OTHER; /** * 17. 指定哪个对象的方法触发一次延迟加载。 */ protected Set<String> lazyLoadTriggerMethods = new HashSet<String>(Arrays.asList(new String[]{"equals", "clone", "hashCode", "toString"})); /** * 18. 指定动态 SQL 生成的默认语言。 */ protected final LanguageDriverRegistry languageRegistry = new LanguageDriverRegistry(); /** * 19. 指定当结果集中值为 null 的时候是否调用映射对象的 setter(map 对象时为 put)方法, * 这对于有 Map.keySet() 依赖或 null 值初始化的时候是有用的。 * 注意基本类型(int、boolean等)是不能设置成 null 的。 */ protected boolean callSettersOnNulls; /** * 20. 当返回行的所有列都是空时,MyBatis默认返回null。 * 当开启这个设置时,MyBatis会返回一个空实例。 * 它也适用于嵌套的结果集 (i.e. collectioin and association)。(从3.4.2开始) */ protected boolean returnInstanceForEmptyRow; /** * 21.指定 MyBatis 增加到日志名称的前缀。 */ protected String logPrefix; /** * 22.指定 MyBatis 所用日志的具体实现,未指定时将自动查找。 */ protected Class<? extends Log> logImpl; /** * 23. 指定 Mybatis 创建具有延迟加载能力的对象所用到的代理工具。默认JAVASSIST * CGLIB | JAVASSIST */ protected ProxyFactory proxyFactory = new JavassistProxyFactory(); // #224 Using internal Javassist instead of OGNL /** * 24.指定VFS的实现(虚拟文件系统) */ protected Class<? extends VFS> vfsImpl; /** * 25.允许使用方法签名中的名称作为语句参数名称。 * 为了使用该特性,你的工程必须采用Java 8编译,并且加上-parameters选项。(从3.4.1开始) */ protected boolean useActualParamName = true; /**26. * Configuration factory class. * Used to create Configuration for loading deserialized unread properties. * * @see <a href='https://code.google.com/p/mybatis/issues/detail?id=300'>Issue 300 (google code)</a> */ protected Class<?> configurationFactory;}
一个配置完整的 settings 元素的示例如下:
<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>
阅读全文
0 0
- 5、Configuration构建之setting节点介绍
- 6、Configuration构建之setting节点解析
- 4、Configuration构建之properties节点
- 7、Configuration构建之typeAliases别名节点解析
- freemarker API 之 Configuration介绍
- SpringBoot构建微服务实战 之 Configuration(一)
- SpringBoot构建微服务实战 之 Configuration(二)
- SpringBoot构建微服务实战 之 Configuration(三)
- Where a configuration setting may be set
- 17.1.1.1 Setting the Replication Master Configuration
- 17.1.1.2 Setting the Replication Slave Configuration
- Setting the Master Configuration on the Slave
- 17.1.1.2 Setting the Replication Slave Configuration
- 17.1.1.2 Setting the Replication Slave Configuration
- 007-logback根节点configuration
- 快速构建网站之介绍wordpress
- Commons Configuration 介绍
- Commons Configuration 介绍
- 4、Configuration构建之properties节点
- Minimum Path Sum
- 编码问题
- 并发插入引发的死锁问题排查
- poj 3728 Catch That Cow bfs搜索 坑点在开两倍数组
- 5、Configuration构建之setting节点介绍
- C++_011_数据结构_循环双链表_混合链表
- 项目中遇到的水平越权漏洞及修复方法
- SQLite数据库的使用
- Java常用设计模式
- Map深入
- String类解析
- linux_时区修改
- JS正则截取首尾单双引号中间内容