JPA SQL插件

  • Post author:
  • Post category:其他


插件功能

  • 还原

    JPA

    输出的日志为完整的

    SQL

    语句。


  • SQL

    日志里面的

    ?

    替换为真正的参数值。
  • 选中要还原的

    JPS

    日志,右键点击菜单

    Restore Sql

    ,还原

    SQL

    语句.

image.png

按钮作用


  • Text

    : 从文本内容还原

    SQL

    语句

  • Settings

    : 配置不想要输出的

    SQL

    语句

  • Format

    : 输出格式化过的

    SQL

    语句

  • Rerun

    : 重启插件

  • Stop

    : 停止插件

插件配置

以springboot工程为例,在

application.yml

文件里面需要配置sql日志的输出级别为:

trace

logging:
  level:
    org.hibernate.type.descriptor.sql.BasicBinder: trace

完整配置示例:

server:
  port: 8080
spring:
  #通用的数据源配置
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
    username: root
    password: root
  jpa:
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    #配置在日志中打印出执行的 SQL 语句信息。
    show-sql: true
    hibernate:
      #配置指明在程序启动的时候要删除并且创建实体类对应的表
      ddl-auto: update
    properties:
      hibernate.format_sql: false
logging:
  level:
    org.hibernate.type.descriptor.sql.BasicBinder: trace

插件窗口左边的Settings按钮配置:


Preparing:

Hibernate:


Parameters:

binding parameter

image.png

日志示例

Hibernate: select userdo0_.id as id1_0_0_, userdo0_.last_login_time as last_log2_0_0_, userdo0_.password as password3_0_0_, userdo0_.sex as sex4_0_0_, userdo0_.user_name as user_nam5_0_0_ from t_user userdo0_ where userdo0_.id=?
2020-10-24 09:45:07.895 TRACE 9980 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [INTEGER] - [1]
Hibernate: update t_user set last_login_time=?, password=?, sex=?, user_name=? where id=?
2020-10-24 09:45:07.949 TRACE 9980 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [TIMESTAMP] - [Sat Oct 24 09:45:07 CST 2020]
2020-10-24 09:45:07.952 TRACE 9980 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [2] as [VARCHAR] - [passWord]
2020-10-24 09:45:07.953 TRACE 9980 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [3] as [INTEGER] - [1]
2020-10-24 09:45:07.954 TRACE 9980 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [4] as [VARCHAR] - [fishpro]
2020-10-24 09:45:07.954 TRACE 9980 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [5] as [INTEGER] - [1]
Hibernate: select userdo0_.id as id1_0_0_, userdo0_.last_login_time as last_log2_0_0_, userdo0_.password as password3_0_0_, userdo0_.sex as sex4_0_0_, userdo0_.user_name as user_nam5_0_0_ from t_user userdo0_ where userdo0_.id=?
2020-10-24 09:45:07.973 TRACE 9980 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [INTEGER] - [1]

插件输出的完整的可执行的

SQL

语句如下:

--  1
 select userdo0_.id as id1_0_0_, userdo0_.last_login_time as last_log2_0_0_, userdo0_.password as password3_0_0_, userdo0_.sex as sex4_0_0_, userdo0_.user_name as user_nam5_0_0_
 FROM t_user userdo0_
 WHERE userdo0_.id=1;
--  ------------------------------------------------------------------------------------------------
--  2
 update t_user set last_login_time='Sat Oct 24 09:45:07 CST 2020', password='passWord', sex=1, user_name='fishpro'
 WHERE id=1;
--  ------------------------------------------------------------------------------------------------
--  3
 select userdo0_.id as id1_0_0_, userdo0_.last_login_time as last_log2_0_0_, userdo0_.password as password3_0_0_, userdo0_.sex as sex4_0_0_, userdo0_.user_name as user_nam5_0_0_
 FROM t_user userdo0_
 WHERE userdo0_.id=1;
--  ------------------------------------------------------------------------------------------------

图片展示

image.png

仓库地址


https://plugins.jetbrains.com/plugin/15242-jpa-sql

销售价格


原价:

$5/年




限时免费



MyBatis Log Plugin作者其他插件列表



版权声明:本文为kookob原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。