properties 标签
优化数据库连接
1. dbconfig.properties文件配置
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///test?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=1949
2. 在SqlMapperConfig.xml中可以引用属性文件中key的值
<?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="dbconfig.properties"/>
<!--development:开发环境,worker工作环境-->
<environments default="development">
<environment id="development">
<!--事务管理采用JDBC-->
<transactionManager type="JDBC"></transactionManager>
<!--连接池-->
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</dataSource>
</environment>
</environments>
<!--注册接口的映射文件-->
<mappers>
<!--
<mapper resource="cn/offcn/dao/UserDao.xml"></mapper>
-->
<!--
<mapper class="cn.offcn.dao.UserDao"></mapper>
-->
<package name="com.wy.dao"></package>
</mappers>
</configuration>