Spring data date between query

Ayan Pal :

I have a query like below:

select * from Products p where ? between  p.effctDate and p.expDate

Can I translate the above query to a spring data jpa query method? Like for example:

findByProductId(productId)

or I only have to use @Query or a Named query to handle such types of queries. I tried searching here first before asking the question as well as spring data site but did not find any solution. any help is appreciated.

Roel Strolenberg :

You could use the following query:

Date date = //Input date
List<Product> = findByEffctDateAfterAndExpDateBefore(date, date);

Note that you have to enter date twice to match both 'where' clauses. This is under the assumption you are using Date objects, not literal Strings.

See JPA Repositories Table 2.3 for more info.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=472873&siteId=1