spring-data-commons
spring-data-commons copied to clipboard
method derivation for Specification<...>
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));