将表单数据转换为对象(DTO)

时间:2017-01-05 10:06:53

标签: java dto

我在控制器中有这条路线接受 - 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对象。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

说,formVars看起来像这样:

public class FormVars{
private String name;
private int age;
//constructors and getters and setters
}`

然后在您的控制器方法中,您需要将@RequestBody MultiValueMap<String, String>替换为@RequestBody FormVars formVars