Reputation: 86627
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?
Upvotes: 0
Views: 1135
Reputation: 1019
So, I see few problems (if it's not mistyping of course):
localhost:8080/myapp¶m=true
"&" isn't correct, you have to use "?" to split params from URL like localhost:8080/myapp?param=true
.@RequestMapping(method = RequestMethod.GET)
(But if you caught the request you've made correct configuration).Upvotes: 0
Reputation: 86627
It turned out I have to omit the @RequestParam
for complex objects:
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public String content(RestDTO restDTO) {
Sysout(restDTO);
}
Upvotes: 0
Reputation: 24403
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.
Upvotes: 1