Annotation Interface RsqlSpec


@Target(PARAMETER) @Retention(RUNTIME) @Documented public @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 Elements
    Modifier and Type
    Required Element
    Description
    The entity class for which the Specification should be built.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Optional field mappings for aliasing entity fields.
    The name of the query parameter that contains the RSQL string.
  • Element Details

    • entityClass

      Class<?> entityClass
      The entity class for which the Specification should be built. This class is used to validate the RSQL query fields and operators against the RsqlFilterable annotations.
      Returns:
      the target entity class
    • fieldMappings

      FieldMapping[] fieldMappings
      Optional field mappings for aliasing entity fields.

      Allows mapping query parameter field names (aliases) to actual entity field names.

      Returns:
      an array of FieldMapping annotations
      Default:
      {}
    • paramName

      String paramName
      The name of the query parameter that contains the RSQL string. Defaults to "filter".
      Returns:
      the HTTP request query parameter name
      Default:
      "filter"