Annotation Interface RsqlSpec
Marks a controller method parameter to be automatically resolved as a
Specification from an RSQL query string.
When applied to a method parameter, the annotated parameter will receive a Specification
built from the RSQL query provided in the HTTP request. The RSQL query is parsed,
validated against the target entity's RsqlFilterable annotations, and converted
into a Spring Data JPA Specification.
Example usage in a controller:
@GetMapping("/users")
public List<User> search(
@RsqlSpec(entityClass = User.class, paramName = "filter") Specification<User> spec
) {
return userRepository.findAll(spec);
}
If the query parameter is not present in the request, the Specification
will be equivalent to Specification.unrestricted(), returning all results.
- See Also:
-
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionClass<?> The entity class for which the Specification should be built. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionOptional field mappings for aliasing entity fields.The name of the query parameter that contains the RSQL string.
-
Element Details
-
entityClass
Class<?> entityClassThe entity class for which the Specification should be built. This class is used to validate the RSQL query fields and operators against theRsqlFilterableannotations.- Returns:
- the target entity class
-
fieldMappings
FieldMapping[] fieldMappingsOptional field mappings for aliasing entity fields.Allows mapping query parameter field names (aliases) to actual entity field names.
- Returns:
- an array of
FieldMappingannotations
- Default:
{}
-
paramName
String paramNameThe name of the query parameter that contains the RSQL string. Defaults to "filter".- Returns:
- the HTTP request query parameter name
- Default:
"filter"
-