springboot集成mybatis控制打印sql语句,不打印执⾏结果集解决办法
jpa mybatismapper 包⽇志级别设置为DEBUG
原因:
Mybatis是⽤Mapper类的全路径名,作为logger的名称的。
Mybatis中,打印SQL语句的⽇志级别是DEBUG,⽽打印SQL执⾏结果集的⽇志级别是TRACE。
下边是笔者的打印⽇志
1 [INFO ] [17:47:14] com.fx.interceptors.ScreenHostInterceptor.preHandle - Request Method Is:public java.lang.Object
ller.LoginController.showCurrentUser(javax.servlet.http.HttpServletRequest)
2 [INFO ] [17:47:14] com.fx.interceptors.ScreenHostInterceptor.preHandle - The Request Method Is:GET
3[DEBUG] [17:47:18] com.fx.mapper.MyTestMapper.findAll.debug - ==>  Preparing: select * from my_t
est;
4[DEBUG] [17:47:19] com.fx.mapper.MyTestMapper.findAll.debug - ==> Parameters:
5[TRACE] [17:47:19] com.fx.mapper.ace - <==    Columns: id, name, age, gender
6[TRACE] [17:47:19] com.fx.mapper.ace - <==        Row: 1, 测试事务mybatis, null, male
7[TRACE] [17:47:19] com.fx.mapper.ace - <==        Row: 2, 测试事务jpa, null, female
8[TRACE] [17:47:19] com.fx.mapper.ace - <==        Row: 4, tom, 4, male
9[TRACE] [17:47:19] com.fx.mapper.ace - <==        Row: 5, hony, 5, male
10[DEBUG] [17:47:19] com.fx.mapper.MyTestMapper.findAll.debug - <==      Total: 4
第3,4⾏为DEBUG级别⽇志  6到10⾏为TRACE级别⽇志
⽐如mapper类所在包名为com.fx.mapper
如果只是想输出sql语句
则在log4j.properties⽂件⾥配置
log4j.logger.fx.mapper=DEBUG
如果既需要打印sql语句也需要打印sql执⾏结果集则修改⽇志级别为TRACE
log4j.logger.fx.mapper=TRACE

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。