zoukankan      html  css  js  c++  java
  • Java -- MyBatis学习笔记3、输出日志

    1、为什么要配置日志?

    在使用MyBatis进行开发时候、每次对数据库操作后在控制台只有结果而没有详细信息。比如:执行添加数据后返回受影响行数、执行查询语句后返回一个对象或者集合,但是、都不知道是执行的那个SQL语句的过程、期间都发生了什么、语句中都有什么值。所以、给MyBatis配置日志,可以输出详细信息,如果结果有错误、可以很快定位到某一个地方。

    1.1、在MyBatis中的主配置文件中加入日志配置

    • 如下:
    <!-- settings:控制mybatis全局行为、告诉mybatis怎么做 -->
    <settings>
        <!--logImpl:输出日志
            STDOUT_LOGGING:输出到控制台
        -->
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>
    
    • 控制台:
    Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
    PooledDataSource forcefully closed/removed all connections.
    PooledDataSource forcefully closed/removed all connections.
    PooledDataSource forcefully closed/removed all connections.
    PooledDataSource forcefully closed/removed all connections.
    Opening JDBC Connection
    Sat May 08 12:16:36 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
    Created connection 84739718.
    Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@50d0686]
    ==>  Preparing: select * from UserInfo 
    ==> Parameters: 
    <==    Columns: id, Name, Age
    <==        Row: 2, 哈哈, 18
    <==        Row: 3, 王五, 16
    <==      Total: 2
    com.rg.entity.UserInfo@396e2f39
    com.rg.entity.UserInfo@a74868d
    Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@50d0686]
    Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@50d0686]
    Returned connection 84739718 to pool.
    

    可以看到、控制台输出的本次结果的执行详细信息、输出日志使用的是StdOutImpl、还有创建连接、关闭连接、SQL语句、行数、最后将对象放回到连接池中等等详细信息。

  • 相关阅读:
    使用 Nginx 内置 $http_user_agent 来区分( 电脑 pc、手机 mobile、平板 pad )端的内容访问
    原创《开源一个用 vue 写的树层级组件 vue-ztree》
    原创《weex面向未来的架构》
    原创《如何用vue来轻松的驾驭 html5 webapp的页面体验》
    Pdf Convert Image 的解决方案
    原创《分享(Angular 和 Vue)按需加载的项目实践优化方案》
    .npmrc 实用小技巧
    使用Tampermonkey,实现Gitlab禁用自我Merge的功能
    vue 之 render 函数不能渲染非全局自定义函数-方案
    反射、注解和动态代理
  • 原文地址:https://www.cnblogs.com/dcy521/p/14744935.html
Copyright © 2011-2022 走看看