mybatis全局配置文件-(1)-properties 属性

1、新建一个dbconfig.properties文件(与mybatis的全局配置文件同目录,也可以不同目录,下面举例是同目录情况下的路径写法),用来保存数据库连接属性。

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis
jdbc.username=root
jdbc.password=123456

orcl.driver=oracle.jdbc.OracleDriver
orcl.url=jdbc:oracle:thin:@localhost:1521:orcl
orcl.username=scott
orcl.password=123456

2、在默认的mybatis的全局配置文件中:

<environments default="development">
	<environment id="development">
		<transactionManager type="JDBC" />
		<dataSource type="POOLED">
			<property name="driver" value="com.mysql.jdbc.Driver" />
			<property name="url" value="jdbc:mysql://localhost:3306/mybatis" />
			<property name="username" value="root" />
			<property name="password" value="Kitty521!" />
		</dataSource>
	</environment>
</environments>

改成

<!--
	1、mybatis可以使用properties来引入外部properties配置文件的内容;
	resource:引入类路径下的资源
	url:引入网络路径或者磁盘路径下的资源
 -->
<properties resource="dbconfig.properties"></properties>

<environments default="dev_mysql">
	<environment id="dev_mysql">
		<transactionManager type="JDBC"></transactionManager>
		<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>
	</environment>
</environments>

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments