如何记录Springboot JPA Pageable绑定值?

时间:2018-02-28 08:20:47

标签: java spring hibernate spring-boot spring-data-jpa

Mysql表

data
----------
id int(11)
keyword varchar(255)
value varchar(255)
score int(11)

存储库代码

public interface DataRepository extends CrudRepository<Data, Long> {
  Page<Data> findByKeywordOrderByScoreDesc(String keyword, Pageable pageable);
}

测试代码

Pageable pageable = PageRequest.of(1, 10);
Page<Data> datas = repository.findByKeywordOrderByScoreDesc("apple", pageable);

记录属性

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

印刷日志

o.h.h.i.QueryTranslatorFactoryInitiator 47 - HHH000397: Using ASTQueryTranslatorFactory
org.hibernate.SQL 92 - select data0_.id as id1_0_, data0_.keyword as keyword2_0_, data0_.value as value3_0_, data0_.score as score4_0_ from data data0_ where data0_.keyword=? order by data0_.score desc limit ?, ?
o.h.type.descriptor.sql.BasicBinder 65 - binding parameter [1] as [VARCHAR] - [apple]
org.hibernate.SQL 92 - select count(data0_.id) as col_0_0_ from data data0_ where data0_.keyword=?
o.h.type.descriptor.sql.BasicBinder 65 - binding parameter [1] as [VARCHAR] - [apple]

日志仅显示data0_.keyword=?绑定值。 我想知道limit ?, ?绑定值。是否有正确的日志设置?

1 个答案:

答案 0 :(得分:0)

您可以将hibernate类型设置为trace以记录绑定值。

spring.jpa.properties.hibernate.type=trace