Annotation Type HasQuery


REST has-query-parameter annotation.

Identifies whether or not an HTTP request has the specified query parameter.

Can be used in the following locations:

  • Arguments and argument-types of server-side @RestOp-annotated methods.

Identical to @HasFormData, but only checks the existing of the parameter in the URL string, not URL-encoded form posts.

Unlike @HasFormData, using this annotation does not result in the servlet reading the contents of URL-encoded form posts. Therefore, this annotation can be used in conjunction with the @Cpmtemt annotation or RestRequest.getContent() method for application/x-www-form-urlencoded POST calls.

Example:

@RestGet public void doGet(@HasQuery("p1") boolean p1) {...}

This is functionally equivalent to the following code:

@RestGet public void doGet(RestRequest req) { boolean p1 = req.getQueryParam("p1").isPresent(); ... }

The parameter type must be either boolean or Boolean.

The following table shows the behavioral differences between @HasQuery and @Query:

Query content @HasQuery("a") @Query("a")
?a=foo true "foo"
?a= true ""
?a true null
?b=foo false null

See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    URL query parameter name.
    A synonym for name().
  • Element Details

    • name

      URL query parameter name. Required. The name of the parameter. Parameter names are case sensitive.
      Notes:
      • The format is plain-text.
      Returns:
      The annotation value.
      Default:
      ""
    • value

      A synonym for name().

      Allows you to use shortened notation if you're only specifying the name.

      The following are completely equivalent ways of defining the existence of a query entry:

      public Order placeOrder(@HasQuery(name="petId") boolean hasPetId) {...}

      public Order placeOrder(@HasQuery("petId") boolean hasPetId) {...}

      Returns:
      The annotation value.
      Default:
      ""