打赏

Java数据持久层框架 MyBatis之API学习三(XML 映射配置文件)

对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html

对于语言的学习而言,马上上手去编程,多多练习是最好的办法。J

XML 映射配置文件

MyBatis 的配置文件包含了影响 MyBatis 行为甚深的设置(settings)和属性(properties)信息。文档的顶层结构如下:

 

 mybatis-config.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
 3 <configuration>
 4     <!-- 属性(properties) -->
 5     <properties resource="test-jdbc.properties"/>
 6     <!-- 设置(settings) -->
 7     <!-- <settings>
 8       <setting name="cacheEnabled" value="true"/>
 9       <setting name="lazyLoadingEnabled" value="true"/>
10       <setting name="multipleResultSetsEnabled" value="true"/>
11       <setting name="useColumnLabel" value="true"/>
12       <setting name="useGeneratedKeys" value="false"/>
13       <setting name="autoMappingBehavior" value="PARTIAL"/>
14       <setting name="autoMappingUnknownColumnBehavior" value="WARNING"/>
15       <setting name="defaultExecutorType" value="SIMPLE"/>
16       <setting name="defaultStatementTimeout" value="25"/>
17       <setting name="defaultFetchSize" value="100"/>
18       <setting name="safeRowBoundsEnabled" value="false"/>
19       <setting name="mapUnderscoreToCamelCase" value="false"/>
20       <setting name="localCacheScope" value="SESSION"/>
21       <setting name="jdbcTypeForNull" value="OTHER"/>
22       <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
23     </settings> -->
24     <!-- 别名(typeAliases) -->
25     <!-- <typeAliases>
26         <typeAlias alias="User" type="com.lanhuigu.mybatis.entity.User"/>
27     </typeAliases> -->
28     <!-- 
29         environments环境
30             *environment 环境变量 
31                 *transactionManager 事务管理器
32                 *dataSource 数据源
33      -->
34      <environments default="development">
35          <environment id="development">
36              <transactionManager type="JDBC"/>
37              <dataSource type="POOLED">
38                  <property name="driver" value="${jdbc.driver}"/>
39                  <property name="url" value="${jdbc.url}"/>
40                  <property name="username" value="${jdbc.username}"/>
41                  <property name="password" value="${jdbc.password}"/>
42              </dataSource>
43          </environment>
44      </environments>
45     <!-- mappers映射器 -->
46     <mappers>
47         <!-- <mapper resource="com/lanhuigu/mybatis/map/UserMainMapper.xml"/> -->
48         <package name="com.lanhuigu.mybatis.map"/>
49     </mappers>
50 </configuration>

 

posted @ 2016-07-26 15:52  海米傻傻  阅读(217)  评论(0编辑  收藏  举报