简体   繁体   中英

How to define the default value for @QueryParam?

When I add the default value of the string in JAX-RS, it doesn't take the value. It stays to null or empty.

@QueryParam("status")
private String status = "confirmed";

When I pass the status as empty or null or undefined it stays as empty or null or undefined. It doesn't take the default as confirmed.

Use the @DefaultValue annotation to specify the default value of the request meta-data that is bound to @PathParam , @QueryParam , @MatrixParam , @CookieParam , @FormParam and @HeaderParam annotations:

@QueryParam("status")
@DefaultValue("confirmed")
private String status;

If a method parameter, resource class field, or resource class bean property is not annotated with @DefaultValue and the corresponding meta-data is not present in the request, the value will be:

  • An empty collection for List , Set or SortedSet .
  • null for other object types;
  • Java-defined default for primitive types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM