1.db.properties
可以将配置信息单独放入db.properties文件中,然后再动态引入
db.properties:k=v(在conf.xml中通过k的值来取v的值)
<configuration>
<properties resource="db.properties"/>
</configuration>
引入之后,使用${key}
(1)db.properties
driver=oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@127.0.0.1:1521:ORCL
username=scott
password=tiger
(2)conf.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 resource="db.properties"/>
<!--
<settings>
<setting name="cacheEnabled" value="false" />
<setting name="lazyLoadingEnabled" value="false" />
</settings>
-->
<!-- 定义别名-->
<typeAliases>
<typeAlias type="nuc.hzb.entity.Student" alias="student"/>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<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>
<mappers>
<mapper resource="nuc/hzb/mapper/studentMapper.xml" />
</mappers>
</configuration>
2.MyBatis全局参数
在conf.xml中设置
<properties resource="db.properties"/>
<!--
<settings>
<setting name="cacheEnabled" value="false" />
<setting name="lazyLoadingEnabled" value="false" />
</settings>
-->
<!-- 定义别名-->
<typeAliases>
<typeAlias type="nuc.hzb.entity.Student" alias="student"/>
</typeAliases>
3.别名
在conf.xml中定义
(1)设置单个别名
<typeAlias type="nuc.hzb.entity.Student" alias="student"/>
(2)批量设置别名
<!-- 定义别名-->
<typeAliases>
<!-- <typeAlias type="nuc.hzb.entity.Student" alias="student"/> -->
<package name="nuc.hzb.entity"/>
<!-- 单个别名(别名忽略大小写)-->
<!-- <typeAlias type="nuc.hzb.entity.Student" alias="student"/> -->
<!-- 批量定义别名 (别名忽略大小写),以下会自动将该包中的所有类批量定义别名:别名就是类名(不带包名,忽略大小写)-->
</typeAliases>
除了自定义别名外,MyBatis还内置了一些常见类的别名