这次分析mybatis的xml文件
1.
<?xml version="1.0" encoding="UTF-8" ?>
<configuration xmlns="http://mybatis.org/schema/mybatis-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mybatis.org/schema/mybatis-config http://mybatis.org/schema/mybatis-config.xsd">
xml编写...
</configuration>
2.资源配置
<!--方法一: 从外部指定properties配置文件, 除了使用resource属性指定外,还可通过url属性指定url-->
<!--方法二. 直接用name,value设置 -->
<properties resource="org/apache/ibatis/builder/jdbc.properties">
<property name="prop1" value="aaaa"/>
<property name="jdbcTypeForNull" value="NULL" />
</properties>
3.setting 标签
代码:
<settings>
<setting name="autoMappingBehavior" value="NONE"/>
<setting name="autoMappingUnknownColumnBehavior" value="WARNING"/>
<setting name="cacheEnabled" value="false"/>
<setting name="proxyFactory" value="CGLIB"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="true"/>
<setting name="multipleResultSetsEnabled" value="false"/>
<setting name="useColumnLabel" value="false"/>
<setting name="useGeneratedKeys" value="true"/>
<setting name="defaultExecutorType" value="BATCH"/>
<setting name="defaultStatementTimeout" value="10"/>
<setting name="defaultFetchSize" value="100"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="safeRowBoundsEnabled" value="true"/>
<setting name="localCacheScope" value="STATEMENT"/>
<setting name="jdbcTypeForNull" value="${jdbcTypeForNull}"/>
<setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString,xxx"/>
<setting name="safeResultHandlerEnabled" value="false"/>
<setting name="defaultScriptingLanguage" value="org.apache.ibatis.scripting.defaults.RawLanguageDriver"/>
<setting name="callSettersOnNulls" value="true"/>
<setting name="logPrefix" value="mybatis_"/>
<setting name="logImpl" value="SLF4J"/>
<setting name="vfsImpl" value="org.apache.ibatis.io.JBoss6VFS"/>
<setting name="configurationFactory" value="java.lang.String"/>
</settings>
4. typeAliases是用来设置类路径别名的
<typeAliases>
<typeAlias alias="User" type="com.majing.learning.mybatis.entity.User"/>
</typeAliases>
别名其他介绍:https://blog.****.net/luoposhushengyizhuce/article/details/80791797
5.mappers配置方式,一看就懂
<mappers>
<mapper resource="org/apache/ibatis/builder/xsd/BlogMapper.xml"/>
<mapper url="file:./src/test/java/org/apache/ibatis/builder/xsd/NestedBlogMapper.xml"/>
<mapper class="org.apache.ibatis.builder.xsd.CachedAuthorMapper"/>
<package name="org.apache.ibatis.builder.mapper"/>
</mappers>
6.数据库标识:databaseIdProvider
️databaseIdProvider的type属性是必须的,不配置时会报错。上面这个属性值使用的是VendorDatabaseIdProvider类的别名。 ️property子元素是配置一个数据库,其中的name属性是数据库名称,value是我们自定义的别名,通过别名我们可以在SQL语句中标识适用于哪种数据库运行。 <databaseIdProvider type="DB_VENDOR">
<property name="Apache Derby" value="derby"/>
</databaseIdProvider> 或者多个:
<!--数据库厂商标示 -->
<databaseIdProvider type="DB_VENDOR">
<property name="Oracle" value="oracle"/>
<property name="MySQL" value="mysql"/>
<property name="DB2" value="d2"/>
</databaseIdProvider>
7.environments 配置数据源:
<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value=""/>
</transactionManager>
<dataSource type="UNPOOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
详细说明:https://blog.****.net/majinggogogo/article/details/71616712
8.typeHandlers type类型注册
<typeHandlers>
<typeHandler javaType="String" handler="org.apache.ibatis.builder.CustomStringTypeHandler"/>
<typeHandler javaType="String" jdbcType="VARCHAR" handler="org.apache.ibatis.builder.CustomStringTypeHandler"/>
<typeHandler handler="org.apache.ibatis.builder.CustomLongTypeHandler"/>
<package name="org.apache.ibatis.builder.typehandler"/>
</typeHandlers>
...
<objectFactory type="org.apache.ibatis.builder.ExampleObjectFactory">
<property name="objectFactoryProperty" value="100"/>
</objectFactory> <objectWrapperFactory type="org.apache.ibatis.builder.CustomObjectWrapperFactory" /> <reflectorFactory type="org.apache.ibatis.builder.CustomReflectorFactory"/> <plugins>
<plugin interceptor="org.apache.ibatis.builder.ExamplePlugin">
<property name="pluginProperty" value="100"/>
</plugin>
</plugins>