Boot显示SQL参数绑定

Boot显示SQL参数绑定

本文介绍了Spring Boot显示SQL参数绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring Boot的新手. sql参数绑定的配置设置是什么.例如,在下面的行中,我应该能够看到所有?"的值.

I am new to spring boot. What is the configuration setting for sql parameter binding. For example in the following line I should be able to see values for all '?'.

选择*从MyFeed WHERE feedId>? AND isHidden = false ORDER BY feedId DESC LIMIT吗?

SELECT * FROM MyFeed WHERE feedId > ? AND isHidden = false ORDER BY feedId DESC LIMIT ?

当前我的配置为

spring.jpa.show-sql:是

spring.jpa.show-sql: true

推荐答案

这只是底层持久性提供程序的提示,例如Hibernate,EclipseLink等.很难知道您正在使用什么.

This is just a hint to the underlying persistence provider e.g. Hibernate, EclipseLink etc. Without knowing what you are using it is difficult to say.

对于Hibernate,您可以配置日志记录以同时输出绑定参数:

For Hibernate you can configure logging to also output the bind parameters:

http://www.mkyong .com/hibernate/how-to-display-hibernate-sql-parameter-values-log4j/

这将为您提供如下输出:

which will give you output like:

Hibernate: INSERT INTO transaction (A, B)
VALUES (?, ?)
13:33:07,253 DEBUG FloatType:133 - binding '10.0' to parameter: 1
13:33:07,253 DEBUG FloatType:133 - binding '1.1' to parameter: 2

一种适用于所有JPA提供程序的替代解决方案是使用log4jdbc之类的东西,它将为您提供更好的输出:

An alternative solution which should work across all JPA providers is to use something like log4jdbc which would give you the nicer output:

INSERT INTO transaction (A, B) values (10.0, 1.1);

请参阅:

https://code.google.com/p/log4jdbc-log4j2/

这篇关于Spring Boot显示SQL参数绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 21:35