------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------
properties整合jdbc.properties
首先准备好jdbc.properties,里面的key值写成jdbc.XXX,因为mabatis中直接写XXX不会报错,但一旦整合Spring之后,说不好咯,容易出问题
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql:///s2228 jdbc.username=root jdbc.password=
其次就是大配置mybatis-config.xml里的事
<?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="jdbc.properties"> </properties> <typeAliases> <package name="cn.dawn.demo01.entity"></package> </typeAliases> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <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> <mappers> <mapper resource="cn/dawn/demo01/dao/IBookDAO.xml"/> </mappers> </configuration>
开一个properties的xml节点,写一个resource="刚才那个文件的名字.后缀名"
之后下面就可以用${value}的方式来获取值填进去