【发布时间】:2016-03-01 13:22:29
【问题描述】:
我正在开发Spring MVC + spring-data-jpa + Hibernate 示例。我正在使用简单的Repository (by extending JpaRepository<T, ID extends Serializable>) 模式对DataSource(DS) 执行查询并获得结果。甚至我也可以根据自己的业务需求编写任何自定义查询。
在进行研究时,我发现了"querydsl-sql" API。该API使用插件,需要使用QueryDslPredicateExecutor<T>like(by
extending JpaRepository<T, ID extends Serializable>,
QueryDslPredicateExecutor<T>)
。但在我看来,这个 API 的功能与 Repository API 的功能相同。
有人可以建议/指导两种方法有什么区别吗?一个使用简单的 Repository,另一个使用 QueryDslPredicateExecutor
List<Customer> findByCustomerNumberAndCustomerId(Integer customerNumber, Integer customerId);
查询dsl方法
@Query("select c from Customer c where c.customerNumber=:customerNumber and c.customerId=:customerId")
List<Customer> findByCustomerNumberAndCustomerId(@Param("customerNumber")
Integer customerNumber, @Param("customerId") Integer customerId);
【问题讨论】:
标签: spring-data-jpa querydsl jpa-2.1