spring -data-mongodb has a really nice and simple query builder. I have several search options that I would like to find, some or nothing can be provided. This is achieved very simply in spring -data-mongodb, and it uses the use of the Pageable and Page classes:
Query query = new Query().with(pageable);
if (searchParameters.getPublished() != null) {
query.addCriteria(Criteria.where("published").is(searchParameters.getPublished()));
}
List<Property> propertyList = mongoTemplate.find(query, Property.class);
long count = mongoTemplate.count(query, Property.class);
List<PropertySummary> propertySummaryList = propertyList.stream()
.map(propertyConverter::convert)
.collect(Collectors.toList());
return new PageImpl<>(propertySummaryList, pageable, count);
Is there anything similar in spring-data-jpa? After spending the day looking around, I would say no. There are api criteria, but they do not integrate with pages of pages and pages, which is very annoying. spring -data-jpa seems great when writing query methods for you where you want to constantly search on a single field. But the library is falling apart very quickly when you fail to do something remotely harder than that findCusomterByLastName(String lastName). If you specify several parameters, all of them must have something specific to search, if one of them is null, then it will correspond to fields that are null.
The api specification seems like a good idea, but you should be able to define your request in one free ad. If you want to conditionally add specifications together, the api will fall apart very quickly.
QueryDslPredicateExecutor, QueryDSL , . -- . , . , , , . ? , , - Specifications.where().and(), (. ).
- ? . - spring -data-jpa, ?