spring-data-commons icon indicating copy to clipboard operation
spring-data-commons copied to clipboard

method derivation for Specification<...>

Open ooraini opened this issue 1 year ago • 2 comments

This is a suggestion.

I was looking into using Specification on a repository. The combinators and/or were interesting, but building the primitive specification with the criteria API seemed rough. Then I thought the technology already exists with method derivation. Something like:

interface Products extends CrudRepository<....> { 
  Specification<Product> byName(String name);
  Specification<Product> byPriceLessThan(BigDecimal price);
)

The client can then combine them:

Products products = ...;
var spec = products.byName("bag").and(products.priceLessThan(BigDecimal.ONE));

ooraini avatar Feb 28 '23 22:02 ooraini