spring-data-jpa 如何在spring-boot中设置hib.format_sql?

mqxuamgl  于 2022-11-10  发布在  Spring
关注(0)|答案(6)|浏览(142)

我使用spring-boot自动配置进行数据库注入,并定义了以下属性:

spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

但是我怎么设置hibernate.format_sql=true呢? Spring Boot 不支持吗?

xytpbqjk

xytpbqjk1#

Sping Boot 将允许您使用以下命令设置任何可用的休眠属性:
spring.jpa.properties.*
因此spring.jpa.properties.hibernate.format_sql=true也可以工作。
请查看文档的这一部分

2mbi3lxu

2mbi3lxu2#

如果使用yml声明Spring Boot属性,则可以使用:

spring:
  datasource:
  jpa:
    properties:
      hibernate.format_sql: true
1qczuiv0

1qczuiv03#

jpa:
  hibernate:
    ddl-auto: update
  show-sql: true
  properties:
    hibernate.format_sql: true
w46czmvw

w46czmvw4#

这是非常可用的

spring.jpa.hibernate.format_sql=true
ifsvaxew

ifsvaxew5#

您可以用途:spring.jpa.properties.hibernate.format_sql=true
除了文档之外,我还按照here中的示例来配置我的应用程序。您可以找到其中使用的属性的示例。

xfyts7mz

xfyts7mz6#

遵循以下属性

Spring.jpa.属性.休眠.格式_sql=true


# Turn Statics On

    spring.jpa.properties.hibernate.generate_statistics=true
    logging.level.org.hibernate.stat=debug

    #Show all queries
    spring.jpa.show-sql=true
    spring.jpa.properties.hibernate.format_sql=true
    logging.level.org.hibernate.type=trace

相关问题