我在控制器中有这条路线接受 - application/x-www-form-urlencoded
@RequestMapping(value = "/browser", method = RequestMethod.POST, produces = {"application/xml"}, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseBody
public ResponseEntity<String> processServerCallback(@RequestBody final MultiValueMap<String, String> formVars) {
System.out.println(formVars);
return null;
}
现在我需要将formVars
转换为我的DTO对象。我怎么能这样做?
答案 0 :(得分:0)
说,formVars看起来像这样:
public class FormVars{
private String name;
private int age;
//constructors and getters and setters
}`
然后在您的控制器方法中,您需要将@RequestBody MultiValueMap<String, String>
替换为@RequestBody FormVars formVars