文件目录
创建proprerties文件如图
jdbc写入
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mydb
jdbc.user=root
jdbc.password=root
mapper.dao=com.guang.dao.Userdao
log4j配置文件
log4j.rootLogger=TRACE,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=wocao.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %F %p %m%n
log4j.logger.mapperNS =TRACE
log4j.logger.com.mybatis=DEBUG
log4j.logger.com.mybatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.mybatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.mybatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.org.springframework=error
log4j.logger.org.apache=ERROR
log4j.logger.org.mybatis=DEBUG
核心配置文件----usertext.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>
<!--配置属性集,下面需要读取配置文件key对应的value-->
<properties resource="jdbc.properties" />
<settings>
<!--配置项目使用log4j的日志输出-->
<setting name="logImpl" value="log4j"/>
</settings>
<typeAliases>
<!-- <typeAlias type="com.qi.bean.User" alias="user"></typeAlias>-->
<!-- <typeAlias type="java.lang.String" alias="string"></typeAlias>-->
<!--加载com.qi.bean包中所有的类,给类默认起别名为类的名字但首字母小写-->
<package name="com.guang.bean"/>
</typeAliases>
<environments default="mysql">
<environment id="mysql">
<transactionManager type="jdbc"></transactionManager>
<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>
</environments>
<mappers>
<mapper class="${mapper.dao}"/>
</mappers>
</configuration>