Annotation Interface FieldMapping
This annotation is used within WebQuery.fieldMappings() to create aliases
for entity fields in filtering and sorting requests. It allows clients to use
simpler or more intuitive names while mapping them to the actual field names
on the entity.
Example usage:
@GetMapping("/users")
@WebQuery(
entityClass = User.class,
fieldMappings = {
@FieldMapping(name = "id", field = "userId"),
@FieldMapping(name = "fullName", field = "profile.name")
}
)
public List<User> search(
@RsqlSpec Specification<User> spec,
@RestrictedPageable Pageable pageable
) {
return userRepository.findAll(spec);
}
In the example above, clients can use id==123 or fullName==John
in their RSQL queries, which will be translated to userId==123 and
profile.name==John respectively.
- See Also:
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether to allow the use of the original field name in addition to the alias.
-
Element Details
-
name
String nameThe alias name to use in API query strings.This is the name that clients will use when constructing their queries.
- Returns:
- the query parameter field name
-
field
String fieldThe actual field name or path on the entity.This can be a simple field name (e.g.,
"userId") or a nested path using dot notation (e.g.,"profile.name").- Returns:
- the entity field name or path
-
allowOriginalFieldName
boolean allowOriginalFieldNameWhether to allow the use of the original field name in addition to the alias.When
false(default), only the alias name defined inname()can be used in filter and sort expressions. Whentrue, both the alias and the original field name are allowed.- Returns:
trueif the original field name should remain usable,falseto enforce exclusive use of the alias
- Default:
false
-