properties标签的使用
xml文件中可以引用外部的properties文件或者本身内部的properties标签,引用方法为${propertyName}。
<appKey>#{localAppKey}</appKey>
在引用本身内部标签时:
<properties>
<property name="localAppKey" value="com.meituan.search.test" />
</properties>
引用外部properties文件:
<properties resource="config.properties"> <!-- 注意,此处的文件路径是xml文件的相对路径 -->
<properties url="file:///C:/home/wangbin/document/config.properties"> <!-- 利用URL定位配置文件的写法,不常用 -->
<properties>
config.properties:
localAppKey="com.meituan.search.test"
别名:typeAliases标签和package标签的使用
在xml文件中,我们可以为一些字符串起别名,以起到简化代码的作用,别名用到的就是typeAlias标签。
<typeAliases>
<typeAlias type="com.meituan.domain.User" alias="user">
</typeAliases>
在配置好别名之后,在使用别名时不区分大小写。
在需要配置大量的别名时,我们可以直接使用package标签。
在使用package标签后,对应包下的所有类都会配置别名,且相应的类名就是别名。
<package name="com.meituan.domain">
</package>