MyBatis配置

数据源配置

# dbConfig.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/数据库名称?characterEncoding=utf-8
username=root
password=******

# 可配置多个数据源,可在mybatis-config.xml文件中通过id切换使用哪种数据源
orcl.driver=com.mysql.jdbc.Driver
orcl.url=jdbc:mysql://192.168.31.185:3306/mybatis?characterEncoding=utf-8
orcl.username=developer
orcl.password=331106

相关配置文件


<configuration>
	
	<properties resource="dbconfig.properties">
		
	properties>
	
	
	
	<settings>
		
		<setting name="mapUnderscoreToCamelCase" value="true"/>
	settings>
	
	
	
	<typeAliases>
		
		<typeAlias type="com.xxx.User" alias="user"/>
		
		<package name="com.xxx.entity"/>
		
	typeAliases>
		
		
	
	<environments default="dev_oracle">
		<environment id="dev_mysql">
			<transactionManager type="JDBC">transactionManager>
			<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>
		<environment id="dev_oracle">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${orcl.driver}" />
				<property name="url" value="${orcl.url}" />
				<property name="username" value="${orcl.username}" />
				<property name="password" value="${orcl.password}" />
			dataSource>
		environment>
	environments>
	
	
	
	<databaseIdProvider type="DB_VENDOR">
		
		<property name="MySQL" value="mysql"/>
		<property name="Oracle" value="oracle"/>
		<property name="SQL Server" value="sqlserver"/>
	databaseIdProvider>
	
	
	
	
	<mappers>
		
		<mapper resource="mybatis/mapper/xxxMapper.xml"/>
		<mapper class="com.xxx.mybatis.dao.xxx"/>
		
		
		<package name="com.xxx.mybatis.dao"/>
	mappers>

你可能感兴趣的:(MyBatis)