Home >Java >javaTutorial >How does SpringBoot print the execution sql problem of mybatis?
should be to track the back-end SQL statements during the development process. What caused the error. The executed SQL statements need to be printed out during the Debug process. So you need to configure SpringBoot and Mybatis to print SQL statements.
Two ways to configure in application.properties(yml):
1. logging.level.dao package name (dao package)=debug
2. mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
2.1. Plan 1 prints all mybatis SQL
The following is the yaml file configuration, and the properties file can be translated
mybatis configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
2.2. Specify the location where the mapper file is located Package
logging: level: cn.com.demos.*.mapper: trace # 改成你的mapper文件所在包路径
For example, I use the second method as follows:
The mybatis configuration in application.yml is modified as follows:
You can see the execution effect as follows:
When debugging a Java project locally, in order to view the specific interaction with the database more intuitively, sometimes SQL printing is required.
Solution 1:
springboot does not enable mybatis log output by default, and you need to manually configure it to enable debug level printing.
Since SpringBoot has introduced spring-boot-starter-logging by default, you only need to configure it, as follows:
logging.level.cn.com.**.web.mapper=debug
Description: "cn.com.**.web.mapper" is the mapper package path.
Option 2:
Add log configuration
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
After configuration, the sql sent by mybatis will be output on the console. It is recommended to use the first way.
The above is the detailed content of How does SpringBoot print the execution sql problem of mybatis?. For more information, please follow other related articles on the PHP Chinese website!