1

What is the simplest way to access an unnamed request parameter in a Spring MVC controller? Is there an annotation for this similar to @RequestParam?

HTTP Delete request with unnamed parameter:

http://localhost/myEndPoint?someUnnamedParam

Controller:

public class MyController {
    @RequestMapping(value = {"/myEndPoint"}, method = RequestMethod.DELETE)
    public void deleteThing() {
        // Do something with unnamed param
    }
}

Details: Spring 3.0.7

4
  • What do mean by "unnamed" parameter? Commented Mar 31, 2014 at 18:50
  • @GriffeyDog it is of the form ?value as opposed to ?name=value Commented Mar 31, 2014 at 18:51
  • How about doing /myEndPoint/value and using @PathVariable? Commented Mar 31, 2014 at 18:53
  • @GriffeyDog I am working from a predefined API and must consume it in the form http://localhost/myEndPoint?someUnnamedParam. Commented Mar 31, 2014 at 18:56

2 Answers 2

4

I think you misunderstand.

In /myEndPoint?someUnnamedParam, you have a parameter named someUnnamedParam with a String value of "", ie. an empty String. It's parsed as an equivalent to /myEndPoint?someUnnamedParam=.

You can get a set of parameter names and use those as values.

@RequestMapping(value = {"/myEndPoint"}, method = RequestMethod.DELETE)
public void deleteThing((@RequestParam Map<String, List<String>> params) {
    Set<String> paramNames = params.keySet();
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

3

You can always use

@RequestMapping(value = {"/myEndPoint"}, method = RequestMethod.DELETE)
public void deleteThing(HttpServletRequest request) {        
    String param = request.getQueryString();
        // Do something with request
}

and perform any operations you need on request

3 Comments

Is there a non Java-EE alternative to HttpServletRequest? Also what method would I call on that to get the unnamed parameter?
@MikeRylander I see you already found the answer to your question :)
Must be the accepted one because it answer the question without asking "why don't you do this in another way?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.