In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how mybatis-plus prints sql logs and parameters to log files under springboot". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to print sql logs and parameters to log files by mybatis-plus under springboot"!
Recently, mybatis-plus has been used in the process of using springboot, and the springboot version is 2.3.1.RELEASE Magi Mybatismurplus version 3.2.0.
Com.baomidou mybatis-plus-boot-starter 3.2.0
Sql logs and parameters need to be printed in use, and many practices on the Internet are to increase the log output configuration.
Mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
In addition, the log does come out after going, and you can see that the sql and parameters are printed out on the idea console.
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@15b67b] was not registered for synchronization because synchronization is not activeJDBC Connection [HikariProxyConnection@6761653 wrapping oracle.jdbc.driver.T4CConnection@1ea226b] will not be managed by SpringJsqlParserCountOptimize sql=SELECT id,password,address,phone,name,email FROM T_USER_TEST3 WHERE name =? = > Preparing: SELECT COUNT (1) FROM T_USER_TEST3 WHERE name =? = > Parameters: zhangsan3 (String) Parameters: zhangsan3 (String)
Log file:
2021-07-22 17 dispatcherServlet'2021 46 INFO 29.254 INFO 38688-[http-nio-8080-exec-6] o.a.c.c.C. [tomcat]. [localhost]. [/ localhost]: Initializing Spring DispatcherServlet'Tomcat-07-22 17 Vantage 46 Vista 29.255 INFO 38688-[http-nio-8080-exec-6] o.s.web.servlet.DispatcherServlet: Initializing Servlet' dispatcherServlet'2021-07-22 17V 4629.268 INFO 38688-[http-nio-8080-exec-6] o.s.web.servlet.DispatcherServlet: Completed initialization in 13 ms2021-07-22 17 o.s.web.servlet.DispatcherServlet 36.869 DEBUG 38688-[http-nio-8080-exec-6] c.b.m.e.p.p.o.JsqlParserCountOptimize: JsqlParserCountOptimize sql=SELECT id Password,address,phone,name Email FROM T_USER_TEST3 WHERE name =? 2021-07-22 17 http-nio-8080-exec-6 46 DEBUG 36.906 DEBUG 38688-[http-nio-8080-exec-6] c.d.d.m.U.pagingBySearchable: = = > Preparing: SELECT COUNT (1) FROM T_USER_TEST3 WHERE name =? 2021-07-22 17 http-nio-8080-exec-6 46 zhangsan3 36. 998 DEBUG 38688-[http-nio-8080-exec-6] c.d.d.m.U.pagingBySearchable: = > Parameters: zhangsan3 (String)
Summary: a total of three configurations are required
1: set the log level under the mybatisplus package to DEBUG
2: set the log level of the project mapper directory to DEBUG
3: set the log output mode of mybatis-plus to slf4j.
Logging.level.com.baomidou.mybatisplus=DEBUG# project mapper directory logging.level.com.dragonsoft.demojar.mapper=DEBUGmybatis-plus.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
Of course, in the production environment, you still need to carefully consider whether to enable sql logging, because logging will be frequent IO, there will be a certain degree of performance loss.
At this point, I believe you have a deeper understanding of "how mybatis-plus prints sql logs and parameters to log files under springboot". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.