LizH
LizH

Reputation: 445

arbitrary parameters in a Spring-boot request

Apologies up front. This should be a 100% google-able question, but I seem to be using the wrong vocabulary.

On an http query, parameters are passed as part of the url string:

curl http://my.host.com/controllerName/actionName?a=b&c=d&e=f&param1=apple&param2=oran

The application specifies a few parameters, and those could be optional:

public HttpEntity<MyResults> actionName(
        @RequestParam(value = "param1", required = true, defaultValue = "Electric Bulb") String param1,
        @RequestParam(value = "param2", required = false ) String param2
        ) throws SomeException { etc}

What I want is if the user passes in some set of params other than what was specified, to capture that in one or more strings to pass downstream. For example, in some languages the 'leftover' query parameters would be a map {param, value}.

Is this possible in Java's type system? If so, how? And what is the right name for them?

Upvotes: 4

Views: 3549

Answers (1)

JB Nizet
JB Nizet

Reputation: 691735

Sure: pass the HttpServletRequest as argument, and use request.getParameterMap() to access all the parameters and their values.

Upvotes: 6

Related Questions