MyBatis的XML配置文件

属性(properties)

通过properties的子元素设置配置项:

<properties>
       <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://localhost:3306/t_mybatis"/>
      <property name="username" value="root"/>
      <property name="password" value="123456"/>
  </properties>

引入外部配置文件:

<properties resource="db.properties"></properties>
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/t_mybatis
jdbc.username=root
jdbc.password=123456

属性在整个XML文件中可用:

<dataSource type="POOLED">
    <property name="driver" value="${jdbc.driver}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
</dataSource>

类型别名(typeAlias)

在使用com.ttpfx.domain.Role的地方,可以使用Role(不区分大小写)代替:

 <typeAliases>
    <typeAlias type="com.ttpfx.domain.Role" alias="Role"></typeAlias>
</typeAliases>

指定包名,com.ttpfx.domain包下的所有类,在未设置注解(@Alias("role"))的情况下,默认使用小写的非限定类名作为别名:

 <typeAliases>
    <package name="com.ttpfx.domain"/>
</typeAliases>

映射(mappers)

mappers也可以导入整个包:

  <mappers>
      <package name="com.ttpfx.dao"/>
  </mappers>
posted @ 2021-03-09 10:00  ttpfx  阅读(99)  评论(0)    收藏  举报