mybatis-config.xml的解释(zz)
2017-09-06 10:47 很大很老实 阅读(320) 评论(0) 编辑 收藏 举报<!-- xml标准格式 -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-/mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<!-- 配置文件根节点 -->
<configuration>
<!--
标签properties
作用:全配置文件中需要用到的键值对,统一管理
使用:标签 ${}
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
</dataSource>
形式:
引入键值对的方式有两种:
一、从外部引入
<properties resource="eas.properties" />
或者
<properties url="eas.properties" />
但不能同时设置两个参数
二、内部写入
<properties>
<property name="username" value="dev_user"/>
<property name="password" value="F2Fa3!33TYyg"/>
</properties>
-->
<properties resource="org/mybatis/example/config.properties">
<property name="username" value="dev_user"/>
<property name="password" value="F2Fa3!33TYyg"/>
</properties>
<!--
标签typeAliases
作用:java类全面一般挺长的,这里用一个别名代替,后面使用时,可直接用别名
形式:
一、<typeAlias alias="Blog" type="domain.blog.Blog"/> 别名自定义
二、<typeAlias type="domain.blog.Author"/> 别名取类的simplename
三、
<typeAliases>
<package name="domain.blog"/>
</typeAliases>
扫描包类,如果有@alias注释,取注释名,没有这取类的simplename
-->
<typeAliases>
<typeAlias type="domain.blog.Author"/>
<typeAlias alias="Blog" type="domain.blog.Blog"/>
</typeAliases>
<!--
标签plugins
-->
<plugins>
<plugin interceptor="org.mybatis.example.ExamplePlugin">
<property name="someProperty" value="100"/>
</plugin>
</plugins>
<!--
标签objectFactory
-->
<objectFactory type="org.mybatis.example.ExampleObjectFactory">
<property name="someProperty" value="100"/>
</objectFactory>
<!--
标签settings
-->
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="multipleResultSetsEnabled" value="true"/>
<setting name="useColumnLabel" value="true"/>
<setting name="useGeneratedKeys" value="false"/>
<setting name="autoMappingBehavior" value="PARTIAL"/>
<setting name="defaultExecutorType" value="SIMPLE"/>
<setting name="defaultStatementTimeout" value="25"/>
<setting name="safeRowBoundsEnabled" value="false"/>
<setting name="mapUnderscoreToCamelCase" value="false"/>
<setting name="localCacheScope" value="SESSION"/>
<setting name="jdbcTypeForNull" value="OTHER"/>
<setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
</settings>
<!--
标签environments
定义MyBatis数据库环境,如连接池、数据库信息、事物管理等
-->
<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="..." value="..."/>
</transactionManager>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<!--
标签databaseIdProvider (不是很明白)
指明数据库这的类型,用于某些特定的SQL方式,比如分页查询语句,一个sql配置文件可配置不同的查询方式,通过databaseId进行多数据提供商的区分
-->
<databaseIdProvider type="DB_VENDOR">
<property name="SQL Server" value="sqlserver"/>
<property name="DB2" value="db2"/>
<property name="Oracle" value="oracle" />
</databaseIdProvider>
<!--
标签typeHandlers
-->
<typeHandlers>
<typeHandler handler="org.mybatis.example.ExampleTypeHandler"/>
</typeHandlers>
<!--
标签mappers
-->
<mappers>
<mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
<mapper resource="org/mybatis/builder/BlogMapper.xml"/>
<mapper resource="org/mybatis/builder/PostMapper.xml"/>
</mappers>
</configuration>