@RequestPart(" json")作为ModelAttribute中的属性

时间:2015-03-16 17:54:10

标签: java spring spring-mvc

有没有办法在Spring MVC中将JSON对象嵌入到模型属性中? 例如,在客户端:

var obj = JSON.parse(user); //user is a json string containing user object info
var formdata =  new FormData();
formdata.append("userInfo",obj);

在服务器端:

@RequestMapping(value = "/here", method = {
            RequestMethod.POST, RequestMethod.GET }, headers = "content-type=multipart/form-data")
    @ResponseBody
    public String doSomething(
    @ModelAttribute MyForm myForm,
            HttpServletRequest request,
            HttpServletResponse response
    ) {
User user = myForm.getUserInfo();
}

0 个答案:

没有答案