在Spring Boot中,SQL语句的参数值被记录为?(问号)。

13 浏览
0 Comments

在Spring Boot中,SQL语句的参数值被记录为?(问号)。

我想将SQL语句记录到文件中。

我在application.properties中有以下属性:

spring.datasource.url=...
spring.datasource.username=user
spring.datasource.password=1234
spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
security.ignored=true
security.basic.enabled=false
logging.level.org.springframework.web=INFO
logging.level.org.hibernate=INFO
logging.file=c:/temp/my-log/app.log

运行我的应用程序时,

cmd> mvn spring-boot:run

我可以在控制台中看到SQL语句,但它们不会出现在app.log中。该文件仅包含来自Spring的基本日志。

我应该怎么做才能在日志文件中看到SQL语句?

admin 更改状态以发布 2023年5月21日
0
0 Comments

这也适用于标准输出:

spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true

记录值:

logging.level.org.hibernate.type=trace

只需将其添加到application.properties中即可。

0
0 Comments

在您的属性文件中尝试使用以下内容:

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

0