0

I want to create a REST service with spring that takes a bunch of parameters. I'd like these parameters to be mapped automatically into a complex transfer object, like:

@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public String content(@RequestParam RestDTO restDTO) {
    Sysout(restDTO); //always null
}

public class RestDTO {
    private boolean param;
    //getter+setter
}

But: when I execute a query like localhost:8080/myapp?param=true the restDTO param remains null.

What am I missing?

3 Answers 3

1

Try with localhost:8080/myapp?param=true.

Probably a case where another pair of eyes sees the obvious :)

EDIT

Remove @RequestParam from method signature, works for me.

Sign up to request clarification or add additional context in comments.

1 Comment

sorry, I of course ment to write myapp?param, edited above.
0

It turned out I have to omit the @RequestParam for complex objects:

@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public String content(RestDTO restDTO) {
    Sysout(restDTO);
}

Comments

0

So, I see few problems (if it's not mistyping of course):

  1. localhost:8080/myapp&param=true "&" isn't correct, you have to use "?" to split params from URL like localhost:8080/myapp?param=true.
  2. I don't see mapping value in @RequestMapping(method = RequestMethod.GET) (But if you caught the request you've made correct configuration).

Comments

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.