- 主页 > 生活百科 > >
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<>();
推荐阅读
-
纪委介入调查结果曝光!那英不当行为坐实后辞职,娱乐圈何去何从
-
-
-
关晓彤|关晓彤穿婚纱高定,小腹隆起被疑怀孕,恋爱7年鹿晗有结婚意向
-
魔兽争霸|魔兽争霸:人族打UD太绝望?TOD放话:不直播War3了
-
京东|京东发布车载户外保温箱:99.9元 垂钓、露营神器
-
#猫哥军备1#自卫队无力应对,求助美方无果,疫情期间俄远洋行动震慑日方
-
本田新款奥德赛实拍!搭2.4L引擎,内饰升级悬浮屏+8座布局
-
-
琉璃美人煞 |《琉璃美人煞》痴心少女变身女王,柳哥心急,司凤拒绝“咸猪手”
-
虎扑|但融入球队的程度还不够,杨鸣:张镇麟很有天赋
-
「EDA365电子论坛」layout,如何学习PCB
-
#深蓝医生#为什么还不实行全国封城?,美国疫情都爆炸了
-
-
-
-
康熙为什么不立大阿哥当太子?康熙为什么不立老八为太子
-
-
央视新闻|尼泊尔加德满都重新封锁首日 1170人因违规外出被罚
-