log4j配置文件中设置mappper方法、类、包级别的日志级别的方法
首先maven的pom文件中
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
第二mapper的xml文件
<?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,如果有多个mapper文件,这个必须唯一 -->
<mapper namespace="com.course.model">
<!--获取登陆接口case-->
<select id="loginCase" parameterType="Integer" resultType="loginCase">
select * from loginCase
where id = #{id}
</select>
<!--添加用户接口case-->
<select id="addUserCase" parameterType="Integer" resultType="addUserCase">
select * from addUserCase where id=#{id}
</select>
<!--获取用户信息case-->
<select id="getUserInfoCase" parameterType="Integer" resultType="getUserInfoCase">
<!-- SQL语句 -->
select * from getUserInfoCase where id=#{id}
</select>
<!--获取用户列表case-->
<select id="getUserListCase" parameterType="Integer" resultType="getUserListCase">
<!-- SQL语句 -->
select * from getUserListCase where id=#{id}
</select>
<!--更新/删除用户信息case-->
<select id="updateUserInfoCase" parameterType="Integer" resultType="updateUserInfoCase">
select * from updateUserInfoCase where id = #{id}
</select>
<!--添加用户接口-->
<select id="addUser" parameterType="com.course.model.AddUserCase" resultType="user">
select * from user where
userName=#{userName}
and password=#{password}
and sex=#{sex}
and age=#{age}
and permission=#{permission}
and isDelete=#{isDelete}
</select>
<!--获取用户信息-->
<select id="getUserInfo" parameterType="com.course.model.GetUserInfoCase" resultType="user">
<!-- SQL语句 -->
select * from user where
id=#{userId}
</select>
<!--获取用户列表-->
<select id="getUserList" parameterType="com.course.model.GetUserListCase" resultType="user">
<!-- SQL语句 -->
select * from user
<where>
<if test="null != userName and '' !=userName">
AND userName=#{userName}
</if>
<if test="null != sex and '' !=sex">
AND sex=#{sex}
</if>
<if test="null != age and '' !=age">
AND age=#{age}
</if>
</where>
</select>
<!--获取更新后的数据-->
<select id="getUpdateUserInfo" parameterType="com.course.model.UpdateUserInfoCase" resultType="user">
select * from user
<where>
<if test="null != userName and '' !=userName">
AND userName=#{userName}
</if>
<if test="null != sex and '' !=sex">
AND sex=#{sex}
</if>
<if test="null != age and '' !=age">
AND age=#{age}
</if>
<if test="null != permission and '' !=permission">
AND permission=#{permission}
</if>
<if test="null != isDelete and '' !=isDelete">
AND isDelete=#{isDelete}
</if>
</where>
And id = #{userId}
</select>
</mapper>
第三 log4j.properties配置mapper的xml文件中的namespace的值
Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=ERROR, CONSOLE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE
#make level of queryAll method DEBUG # method level
#log4j.logger.com.bjsxt.mapper.PeopleMapper.queryAll=DEBUG
#log4j.logger.com.bjsxt.mapper.PeopleMapper.query2=DEBUG
class level
#log4j.logger.com.bjsxt.mapper.PeopleMapper=DEBUG
packet level,原来这里写的是mapper.xml中命名空间namespace的值
log4j.logger.com.course.model=DEBUG
CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#this “-” means that it will writes what you write
log4j.appender.CONSOLE.layout.ConversionPattern=- %p %m%n
LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=E:/myclipse/Workspaces/MyEclipse 2017 CI/1030_log4j/log/test.log
#true is added at end,false is overwrite
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
然后运行如下
本文地址:https://blog.csdn.net/thgjkgdrf/article/details/110687390
下一篇: MySQL找出未提交事务的SQL实例浅析