Closed
Description
When processing an HttpRequest
with x-www-form-urlencoded
content, we can use a controller with POJO matching the payload structure.
Example payload: value_first=value1&value_second=value2
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String handlePost(@ModelAttribute Body body) {
}
POJO:
public class Body {
private String value_first;
private String value_second;
}
The problem is that the variable names must match the field names in the HttpRequest
payload in order to be processed by the controller. There is not way of naming them differently, for example, if I do not want to use underscopes in Java variable and method names.
What I would appreciate would be using something like this:
@FormAttribute
private String value1;