- 主页 > 生活百科 > >
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<>();
推荐阅读
-
-
日本_社会|中国男子在东京街头对日本女孩耍流氓被抓
-
-
封神榜是谁最后出现占了姜子牙的神位?姜子牙与封神榜的关系
-
安福真历史|来“激励”士兵,二战时的日本女人到底有多疯狂?将身体作为武器
-
-
大邑县人民检察院 百姓便利多(大数据观察),电子社保卡
-
-
鹿晗|央视亲自点名!鹿晗新剧登上《今日说法》,归国四子他已脱颖而出
-
好六网|DNF:刚当没几天第一,似雨幽离又没忍住,剑宗装备又毁了!
-
视阁国际|要求墨西哥入境车辆交钱,墨西哥:你做梦,特朗普又打边境墙主意
-
数据|6个月三次被关注问询!惠程科技核心数据降幅不匹配,到底怎么了?
-
-
-
美国警察暴力狠手遭曝光■专挑脑袋打 美国警察暴力狠手遭曝光
-
枫无痕|只为引老伴跟踪,夫妻发生信任危机源于猜忌,70岁老人午夜外出
-
惠普m233sdw怎么复印-惠普m230sdn扫描步骤-
-
-
脑梗塞|脑梗塞不是突然到来,患上脑梗塞的人,睡觉前常常有四个共同点
-
五菱|五菱凯捷正式下线,6座布局带魔术座椅,实车尺寸超奥德赛!