- 主页 > 生活百科 > >
mybatis3 源码深度解析-Configuration 对象深入了解
- 1是主配置文件 mybatis-config.xml
- 2是配置执行 sql 的 MApper文件(接口或者 xml)
- mybatis 定义了一系列属性来控制 mybatis 运行时的行为,这些属性可以在主配置通过 <setting>标签指定
- mybatis 所有属性的含义可以在官方文档查看 https://mybatis.org/mybatis-3/zh/configuration.html#settings
【mybatis3 源码深度解析-Configuration 对象深入了解】Configuaration 类字段注释
public class Configration {protected Environment environment;// 允许 JDBC 支持自动生成主键 , 需要驱动兼容 。// 这就是insert时获取MySQL自增主键/oracle sequence的开关 。// 注:一般来说,这是希望的结果,应该默认值为true比较合适 。protected boolean useGeneratedKeys;// 是否启用缓存protected boolean cacheEnabled = true;// 指定 MyBatis 增加到日志名称的前缀 。protected String logPrefix;// 指定 MyBatis 所用日志的具体实现 , 未指定时将自动查找 。一般建议指定为slf4j或log4jprotected Class<? extends Log> logImpl;// 当没有为参数提供特定的 JDBC 类型时 , 为空值指定 JDBC 类型 。某些驱动需要指定列的 JDBC 类型 , 多数情况直接用一般类型即可 , 比如 NULL、VARCHAR 或 OTHER 。protected JdbcType jdbcTypeForNull = JdbcType.OTHER;// settings下的properties属性protected Properties variables = new Properties();// 默认的反射器工厂,用于操作属性、构造器方便protected ReflectorFactory reflectorFactory = new DefaultReflectorFactory();// 对象工厂, 所有的类resultMap类都需要依赖于对象工厂来实例化protected ObjectFactory objectFactory = new DefaultObjectFactory();// 对象包装器工厂,主要用来在创建非原生对象,比如增加了某些监控或者特殊属性的代理类protected ObjectWrapperFactory objectWrapperFactory = new DefaultObjectWrapperFactory();// 延迟加载的全局开关 。当开启时 , 所有关联对象都会延迟加载 。特定关联关系中可通过设置fetchType属性来覆盖该项的开关状态 。protected boolean lazyLoadingEnabled = false;// 指定 Mybatis 创建具有延迟加载能力的对象所用到的代理工具 。MyBatis 3.3+使用JAVASSISTprotected ProxyFactory proxyFactory = new JavassistProxyFactory(); // #224 Using internal Javassist instead of OGNL// MyBatis 可以根据不同的数据库厂商执行不同的语句 , 这种多厂商的支持是基于映射语句中的 databaseId 属性 。protected String databaseId;/** * configuration 存储属性之外的数据: 类型处理 TypeHandler,类型别名typeAlias,Mapper接口 * 以下字段信息会在启动的时候注册到 configuration 对象 */// 存储namespace与MapperProxyFactory<mapper接口> 对应关系Map<Class<?>, MapperProxyFactory<?>> knownMappers = new HashMap<>();protected final MIniMapperRegistry mapperRegistry = new MIniMapperRegistry(this);// mybatis插件列表List<Interceptor> interceptors = new ArrayList<>();protected final InterceptorChain interceptorChain = new InterceptorChain();// 类型注册器,TypeAliasRegistry 构造器会添加默认值// 用于在执行sql语句的出入参映射以及mybatis-config文件里的各种配置// 比如<transactionManager type="JDBC"/><dataSource type="POOLED">时使用简写// Map<String, Class<?>> typeAliases存储key别名 , value 类型protected final TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry();//Java和jdbc类型互相转换protected final TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry();protected final LanguageDriverRegistry languageRegistry = new LanguageDriverRegistry();protected ResultSetType defaultResultSetType;//mapper.xml 中每条select|insert|update|delete 语句的映射protected final Map<String, MappedStatement> mappedStatements = new StrictMap<MappedStatement>("Mapped Statements collection").conflictMessageProducer((savedValue, targetValue) ->". please check " + savedValue.getResource() + " and " + targetValue.getResource());protected final Map<String, Cache> caches = new StrictMap<>("Caches collection");//Mapper.xml 通过 <ResultMap> 配置的结果集映射关系信息protected final Map<String, ResultMap> resultMaps = new StrictMap<>("Result Maps collection");//Mapper.xml 通过 <ParameterMap> 配置的入参映射关系信息protected final Map<String, ParameterMap> parameterMaps = new StrictMap<>("Parameter Maps collection");//KeyGenerator 是mybatis主键生成器 : mybatis提供了 3 中主键生成器 1:jdbc3KeyGenerator(数据库自增主键) 2:SelectKeyGenerator (通过 select 语句查询,如 oracle sequence) 3:noKeyGenerator(无自增主键)protected final Map<String, KeyGenerator> keyGenerators = new StrictMap<>("Key Generators collection");// 注册所有 Mapper.xml 的存放路径protected final Set<String> loadedResources = new HashSet<>();protected final Map<String, XNode> sqlFragments = new StrictMap<>("XML fragments parsed from previous mappers");/** * 以下用于注册出现解析异常的相关对象 */protected final Collection<XMLStatementBuilder> incompleteStatements = new LinkedList<>();protected final Collection<CacheRefResolver> incompleteCacheRefs = new LinkedList<>();protected final Collection<ResultMapResolver> incompleteResultMaps = new LinkedList<>();protected final Collection<MethodResolver> incompleteMethods = new LinkedList<>();
推荐阅读
-
张继聪|入围两奖皆失落!港知名男星曾被嘲废柴老公,因靠TVB走向小高峰
-
表面“貌若天仙”,实则“歪瓜裂枣”的5大女星,个个整得惊艳
-
-
喝菊苣茶一个月尿酸反而高了为什么,尿酸不高可以喝菊苣栀子茶吗
-
直播吧|身先士卒!沃克命中压哨三分首节轰下17分带队领先
-
-
宅秘 安全大功率售价79元,米家插线板27W快充版正式开售
-
-
张宇浩|美国三大股指10月1日全线上涨 纳指涨超1.4%
-
#菜篮子#“一站式”服务!粤港澳大湾区“菜篮子”通关(增城)便利区启用
-
抖音达人pick计划是什么?怎么参与? 什么是抖音pick计划
-
visio2007永久激活密钥 visio2010永久激活密钥
-
约基奇|约基奇穆雷半场合砍44分,掘金两节比赛拿下恐怖72分
-
职业教育|“宁可让学生打工也别去读职高”,家长激愤发言,引起共鸣!
-
一线|弯腰捡个手机,突然...... | 一线微观
-
香港警察截查可疑男子时遭袭受伤,多人合力将嫌犯拘捕
-
-
连锁门店商品的更新率一般控制在多少以下 淘宝全球购入驻要求
-
-