1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" 3 "http://mybatis.org/dtd/mybatis-3-config.dtd"> 4 <!-- 数据源的信息:数据库的信息。 --> 5 <configuration> 6 <environments default="development"> 7 <environment id="development"> 8 <transactionManager type="JDBC" /> 9 <dataSource type="POOLED"> 10 <property name="driver" value="com.mysql.jdbc.Driver" /> 11 <property name="url" value="jdbc:mysql://localhost:3306/mybatis" /> 12 <property name="username" value="root" /> 13 <property name="password" value="root" /> 14 </dataSource> 15 </environment> 16 </environments> 17 18 </configuration>
# 数据源信息 driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/mybatis username=root password=root
<?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="com.zhiyou100.mcl.mapper.UsersMapper"> <select id="getUser" parameterType="int" resultType="com.zhiyou100.mcl.bean.Users"> select * from users where id=#{id} </select> <insert id="addUser" parameterType="com.zhiyou100.mcl.bean.Users"> insert into users(name,age) values(#{name},#{age}) </insert> <delete id="deleteUser" parameterType="int"> delete from users where id=#{id} </delete> <update id="updateUser" parameterType="com.zhiyou100.mcl.bean.Users"> update users set name=#{name},age=#{age} where id=#{id} </update> <select id="selectAll" resultType="Users"> select * from users </select> <select id="selectByAge" parameterType="map" resultType="Users"> <![CDATA[select * from users where age>=#{min} and age<=#{max}]]> </select> </mapper>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" 3 "http://mybatis.org/dtd/mybatis-3-config.dtd"> 4 <configuration> 5 <!-- 引入属性文件 --> 6 <properties resource="jdbc.properties"></properties> 7 <!-- 为实体类起别名 --> 8 <typeAliases> 9 <!-- <typeAlias type="com.zhiyou100.mcl.bean.Users" alias="user"/> --> 10 <package name="com.zhiyou100.mcl.bean"/> 11 </typeAliases> 12 <environments default="development"> 13 <environment id="development"> 14 <transactionManager type="JDBC" /> 15 <dataSource type="POOLED"> 16 <property name="driver" value="${driver}" /> 17 <property name="url" 18 value="${url}" /> 19 <property name="username" value="${username}" /> 20 <property name="password" value="${password}" /> 21 </dataSource> 22 </environment> 23 </environments> 24 <-- 多个映射文件放入到同一mappers个里--> 25 <mappers> 26 <mapper resource="com/zhiyou100/mcl/mapper/UsersMapper.xml"/> 27 <mapper resource="com/zhiyou100/mcl/mapper/OrderMapper.xml"/> 28 <mapper resource="com/zhiyou100/mcl/mapper/ClazzMapper.xml"/> 29 </mappers> 30 </configuration>
log4j.properties, log4j.rootLogger=DEBUG, Console #Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n log4j.logger.java.sql.ResultSet=INFO log4j.logger.org.apache=INFO log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG
原文:https://www.cnblogs.com/mcl2238973568/p/11432495.html