如何在Spring-Data-JPA存储库中重用参数? [英] How do I reuse a parameter witha Spring-Data-JPA Repository?
本文介绍了如何在Spring-Data-JPA存储库中重用参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
In looking at the Query Creation for the Spring Data JPA Repositories, I'm wondering how I would reuse a parameter. For example, how would I name the method if I wanted to do something like:
@Query("select c from #{#entityName} c where c.lower <= ?1 and c.upper >= ?1")
E findByConversionFor(Double amount);
该查询可以转换为SpEL方法名称(由查询生成器使用)吗?
Can that query be converted to a SpEL method name (to be used by the query builder)?
要求两次传递相同的值似乎很麻烦:
It seems like a kludge to require the same value to be passed twice:
E findByLowerLessThanOrEqualAndUpperGreaterThanOrEqual(Double a, Double b); // where a==b
推荐答案
只需用@Param("amount")
标记您的参数,然后就可以按名称使用它:
Just mark your parameter with @Param("amount")
and then will be able to use it by name:
@Query("select c from #{#entityName} c where c.lower <= :amount and c.upper >= :amount")
这篇关于如何在Spring-Data-JPA存储库中重用参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文