I have a simple controller method with more than 7 parameters and would like to refactor it using a model object instead, ie to extract a parameter object:
@RequestMapping(value="/{one}")
public String controllerMethod(@PathVariable(value="one") String one, @RequestParam String two, ... @RequestBody body) {
...
}
I tried to extract an object with setters and getters and pathVariable and requestParameters are mapped by name. However I have troubles making the same for @RequestBody, it doesn't work for me even if I put @RequestBody into setter...
public class Parameters {
private String one; // pathVariable
private String two; // requestParameter
private String body;// requestBody - always NULL!
// other fields definition
public setBody(@RequestBody String body) {this.body = body}
//other setters/getters
}
public void setOne(@RequestParameter(value="o") String one) {this.one = one}
For the (1) I would simply keep @RequestBody as a separate parameter though I don't like it much.
Ok, looks like the only way of doing (2) and (3) is through customizing data binding: the similar question
Feel free to post another easy solution if you know about it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.