基于mybatis打印sql语句耗时(Mybatis开启控制台打印sql语句的三种方式)

springboot mybatis整合过程中,开启控制台sql语句打印的多种方式:

附:mybatis官方文档

方法一:

1>(spring mybatis)在mybatis的配置文件中添加:

<settings> <!-- 打印sql日志 --> <setting name="logImpl" value="STDOUT_LOGGING" /> </settings>

mybatis的配置文件----mybatis-config.xml如下:

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <!-- 打印sql日志 --> <setting name="logImpl" value="STDOUT_LOGGING" /> </settings> </configuration>

2> (springboot mybatis)在springboot的配置文件----appcation.yml中添加:

mybatis: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

ps:

IDEA中,springboot默认配置文件是application.properties文件,但是yml文件在语法上更加简洁,更有层次感,所以此处是用yml语法,properties中好像是这么写的:mybatis.configuration.log-impl= org.apache.ibatis.logging.stdout.StdOutImpl

控制台可以打印了。。。。。

基于mybatis打印sql语句耗时(Mybatis开启控制台打印sql语句的三种方式)(1)

方法二:

在springboot mybatis整合中,可以将springboot的配置文件添加如下一段也可:

logging: level: com.fish.mybatis.mapper: debug

基于mybatis打印sql语句耗时(Mybatis开启控制台打印sql语句的三种方式)(2)

基于mybatis打印sql语句耗时(Mybatis开启控制台打印sql语句的三种方式)(3)

其中com.fish.mybatis.mapper是包名

方法三:

如果你使用的是springboot mybatis-plus的话:

<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.1</version> </dependency>

application.yml:

mybatis-plus: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

控制台打印:

jdbc Connection [HikariProxyConnection@1006460161 wrapping com.mysql.cj.jdbc.ConnectionImpl@37cccae8] will not be managed by Spring ==> Preparing: select * from t_user where id = ? ==> Parameters: 1(Integer) <== Columns: id, user_name, age <== Row: 1, 张三, 18 <== Total: 1

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页