mybatis 核心配置文件
<?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="database.properties"/>--> <!--当propeties的name属性一致的时候,resources文件中的优先级会更高--> <properties resource="database.properties"> <!--<property name="jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="jdbc.url" value="jdbc:mysql://127.0.0.1:3306/smbms"/> <property name="jdbc.user" value="root"/> <property name="jdbc.password" value="123456"/>--> </properties> <settings> <setting name="logImpl" value="LOG4J"/> <setting name="lazyLoadingEnabled" value="false"/> <!--partial 部分的-FULL NONE(手动映射 resultMap)--> <setting name="autoMappingBehavior" value="PARTIAL"/> </settings> <typeAliases> <!-- <typeAlias type="com.mybatis.pojo.User" alias="u"></typeAlias>--> <package name="com.mybatis.pojo"/> </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.user}"/> <property name="password" value="${jdbc.password}"/> </dataSource> </environment> <environment id="test"> <transactionManager type="JDBC"/> <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> </environments> <mappers> <!--<mapper resource="com/mybatis/dao/UserMapper.xml"></mapper>--> <!--<mapper class="com.mybatis.dao.UserMapper"></mapper>--> <!--全局唯一资源定位 uniform resource locator http://127.0.0.1:8080/Servlet--> <!-- <mapper url="file:///D:/IdeaProjects/mybatis/mybatisdemo01/src/main/resources/com/mybatis/dao/UserMapper.xml"></mapper>--> <package name="com.mybatis.dao" ></package> </mappers> </configuration>
database.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/smbms?useUnicode=true&characterEncoding=UTF-8 jdbc.user=root jdbc.password=123456
mapper.xml中
<!--可复用的sql语句片段--> <sql id="query"> select * from smbms_user </sql> <select id="findAllUser" resultType="com.mybatis.pojo.User"> /* select * from smbms_user;*/ <include refid="query"/> </select>
<settings> <setting name="logImpl" value="LOG4J"/> <setting name="lazyLoadingEnabled" value="false"/> <!--partial 部分的-FULL NONE(手动映射 resultMap)--> <setting name="autoMappingBehavior" value="PARTIAL"/> </settings>