<?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="db.properties"></properties>
<settings>
<!-- 开启驼峰命名 -->
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
<!-- 配置坏境 -->
<environments default="dev_mysql">
<environment id="dev_mysql">
<!-- 配置事务管理器 -->
<transactionManager type="JDBC"></transactionManager>
<!-- 配置数据源 -->
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driverclass}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</dataSource>
</environment>
<environment id="dev_orcle">
<!-- 配置事务管理器 -->
<transactionManager type="JDBC"></transactionManager>
<!-- 配置数据源 -->
<dataSource type="POOLED">
<property name="driver" value="${oracle.driverclass}" />
<property name="url" value="${oracle.url}" />
<property name="username" value="${oracle.username}" />
<property name="password" value="${oracle.password}" />
</dataSource>
</environment>
</environments>
<!-- 配置连接多种数据库 -->
<databaseIdProvider type="DB_VENDOR">
<!-- 注意此处容易出错:原因将MySQL写成了Mysql -->
<property name="MySQL" value="mysql"/>
<property name="SQL Server" value="sqlserver" />
<property name="DB2" value="db2" />
<property name="Oracle" value="oracle" />
</databaseIdProvider>
<!-- 映sql映射文件 -->
<mappers>
<!-- 批量注册sql映射文件 -->
<package name="zhang.mybatis.dao"/>
</mappers>
</configuration>
jdbc.username=root
jdbc.password=zhangyukang
jdbc.driverclass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis
#jdbc.user=scott
#jdbc.password=305316
#jdbc.driverclass=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@localhost:1521:orcl
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="zhang.mybatis.dao.CustomerMapper" >
<select id="getCustomerById" resultType="zhang.mybatis.test.Customer" databaseId="mysql">
select * from Customer
where id = #{id}
</select>
<select id="getAllCustomer" resultType="zhang.mybatis.test.Customer" databaseId="mysql" >
select * from Customer
</select>
<select id="saveCustomer" parameterType="zhang.mybatis.test.Customer" databaseId="mysql" >
Insert into Customer(id,name,age,email) values
(#{Customer.id},#{Customer.name},#{Customer.age},#{Customer.email})
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="zhang.mybatis.dao.PersonMapper" >
<select id="getPersonById" resultType="zhang.mybatis.entities.Person" databaseId="mysql" >
select * from
Person where
id = #{id}
</select>
<select id="getPersonByName" resultType="zhang.mybatis.entities.Person" databaseId="mysql" >
select * from Person
where last_Name = #{lastName}
</select>
</mapper>