Java 如何在 spring-boot 中设置 hibernate.format_sql?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25720396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:00:20  来源:igfitidea点击:

How to set hibernate.format_sql in spring-boot?

javaspringspring-bootspring-data-jpa

提问by membersound

I'm using spring-bootautoconfiguration for database injection, with properties defined:

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

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

But how can I set the hibernate.format_sql=true? Is that not supported by spring boot?

但是我该如何设置hibernate.format_sql=true?弹簧靴不支持吗?

采纳答案by geoand

Spring Boot will let you set any available hibernate property using:

Spring Boot 将允许您使用以下方法设置任何可用的休眠属性:

spring.jpa.properties.*

spring.jpa.properties.*

So spring.jpa.properties.hibernate.format_sql=truewould work as well.

所以spring.jpa.properties.hibernate.format_sql=true也会起作用。

Check out thispart of the documentation

查看文档的这一部分

回答by Ankur Singhal

This is very much available

这是非常可用的

spring.jpa.hibernate.format_sql=true

回答by VinayVeluri

You can use : spring.jpa.properties.hibernate.format_sql=true

您可以使用 : spring.jpa.properties.hibernate.format_sql=true

Apart from the documentation, I do follow example from hereto configure my application. You can find a sample of properties being used in that.

除了文档之外,我确实按照此处的示例来配置我的应用程序。您可以找到其中使用的属性示例。

回答by Andrii Abramov

If you are using ymlformat to declare Spring Boot properties, you can use:

如果您使用ymlformat 来声明 Spring Boot 属性,则可以使用:

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

回答by xiaogege

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