2

I have such a Interface:

interface ItemRepository extends JpaRepository<Item, Integer> {
    Item findItemByName(String name);
    Collection<Item> findItemByCategory(String category);
}

it does the job without implementation already, but I have to add the following statement:

select from Item where quantity < 10;

2 Answers 2

2

Spring Data JPA supports the LessThan keyword inside method names. In your case, the signature of the method would be:

Collection<Item> findItemByQuantityLessThan(int upperBound);

You can then call this method giving it 10 as parameter to have your result.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use LessThan identifier or use a custom query like this :

@Query("SELECT i FROM Item i WHERE i.quantity < :quantity")
public List<Item> findByCategory(@Param("quantity") int quantity);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.