springboot集成mybatis控制打印sql语句,不打印执行结果集

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

springboot集成mybatis控制打印sql语句,不打印执⾏结果集
解决办法
mapper 包⽇志级别设置为DEBUG
原因:
Mybatis是⽤Mapper类的全路径名,作为logger的名称的。

Mybatis中,打印SQL语句的⽇志级别是DEBUG,⽽打印SQL执⾏结果集的⽇志级别是TRACE。

下边是笔者的打印⽇志
1 [INFO ] [17:47:14] com.fx.interceptors.ScreenHostInterceptor.preHandle - Request Method Is:public ng.Object com.fx.controller.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_test;
4[DEBUG] [17:47:19] com.fx.mapper.MyTestMapper.findAll.debug - ==> Parameters:
5[TRACE] [17:47:19] com.fx.mapper.MyTestMapper.findAll.trace - <== Columns: id, name, age, gender
6[TRACE] [17:47:19] com.fx.mapper.MyTestMapper.findAll.trace - <== Row: 1, 测试事务mybatis, null, male
7[TRACE] [17:47:19] com.fx.mapper.MyTestMapper.findAll.trace - <== Row: 2, 测试事务jpa, null, female
8[TRACE] [17:47:19] com.fx.mapper.MyTestMapper.findAll.trace - <== Row: 4, tom, 4, male
9[TRACE] [17:47:19] com.fx.mapper.MyTestMapper.findAll.trace - <== 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⽂件⾥配置
.fx.mapper=DEBUG
如果既需要打印sql语句也需要打印sql执⾏结果集则修改⽇志级别为TRACE
.fx.mapper=TRACE
参考资源。

相关文档
最新文档