mybatis启动过程分析五setting解析

objectFactory和objectWrapperFactory平时用的很少主要是mybatis内部反射用,几乎不会涉及暂不分析,后面有空补上。
本章分析setting分析

configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
    configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
    configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
    configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), false));
    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
    configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
    configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
    configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
    configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
    configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
    configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
    configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
    configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
    configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
    configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
    configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
    configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
    configuration.setReturnInstanceForEmptyRow(booleanValueOf(props.getProperty("returnInstanceForEmptyRow"), false));
    configuration.setLogPrefix(props.getProperty("logPrefix"));
    @SuppressWarnings("unchecked")
    Class<? extends Log> logImpl = (Class<? extends Log>)resolveClass(props.getProperty("logImpl"));
    configuration.setLogImpl(logImpl);
    configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));

这个其实就没什么可以分析的,提几个比较常用的
configuration.setCacheEnabled(booleanValueOf(props.getProperty(“cacheEnabled”), true));是否开启二级缓存
Class<? extends Log> logImpl = (Class<? extends Log>)resolveClass(props.getProperty(“logImpl”));
configuration.setLogImpl(logImpl);日志的实现类。
其他的几乎很少用到

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: mybatis 使用 mapperElement 解析器来解析 mapper 配置文件。 在解析过程中,mapperElement 解析器会读取 mapper 配置文件中的信息,并根据相应的规则和语法来解析文件内容。 一般来说,mapper 配置文件中包含了每一个 SQL 语句的映射信息,包括 SQL 语句本身、参数类型、返回结果类型等。 在解析过程中,mapperElement 解析器会将这些信息转化为可以由 mybatis 框架使用的对象,以便在之后的操作中使用。 总的来说,mapperElement 解析器的工作就是将 mapper 配置文件中的信息转化为可以被 mybatis 框架使用的对象,以便在之后的操作中使用。 ### 回答2: Mybatis是一个开源的持久层框架,而mapperElement是Mybatis中用于解析Mapper文件的一个重要组件。 Mybatis的Mapper文件是一种存储SQL映射关系的XML文件。当Mybatis框架在运行时读取和解析Mapper文件时,就会利用mapperElement进行解析过程。 mapperElement的解析过程主要涉及以下几个步骤: 1. 解析命名空间(namespace):首先,mapperElement会解析Mapper文件中的命名空间,用于标识该Mapper文件所对应的Java接口或类。解析过程中会确保命名空间唯一,并与对应的Java类绑定。 2. 解析SQL语句:接下来,mapperElement会解析Mapper文件中的SQL语句,包括select、insert、update和delete等操作。解析过程中会提取出SQL语句的类型、参数类型和返回值类型等信息。 3. 解析SQL语句的参数映射:对于SQL语句中的参数,mapperElement会解析参数映射关系。解析过程中会根据参数类型和方法中的参数注解进行匹配,确保正确的参数映射。 4. 解析SQL语句的结果映射:对于SQL语句的结果,mapperElement会解析结果映射关系。解析过程中会根据返回值类型和结果集中的列名进行匹配,确保正确的结果映射。 5. 解析其他配置信息:除了SQL语句的解析,mapperElement还会解析其他配置信息,如缓存配置、参数拦截器配置等。解析过程中会检查配置的合法性,并将配置信息保存起来,以供Mybatis框架的使用。 通过以上的解析过程,mapperElement能够了解Mapper文件的结构和内容,并将其转化为Mybatis框架内部可识别和执行的对象。这些对象将提供给Mybatis框架进行数据库操作,确保了数据的正确性和准确性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值