@RestController @RequestMapping("/testController") public class TestController { @RequestMapping(value = "test1",method = RequestMethod.POST) public void test1(Person person) { System.out.println(person.getName()); System.out.println(person.getBirthday()); }
}
--------------------------------------------------
Person类
public class Person { String name; @JSONField(format = "yyyy-MM-dd") Date birthday; public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } }
-------------------------------------------------
你这个是pringmvc使用form-data 格式不支持。可以参考这个blog:
https://blog.csdn.net/qq_30038111/article/details/82885225 希望能帮到你
能把请求发出来吗。对代码层面看是没有问题的
老哥,需要加@RequestBody
要实现可序列化接口,不然不能用于数据传输
public class Person implements Serializable
public static Map<String, Object> buildRequestParams(HttpServletRequest request, Map<String, Object> params){
Enumeration enu = request.getParameterNames();
while (enu.hasMoreElements()) {
String paramName = CommUtil.toString(enu.nextElement());
String paramVal = CommUtil.toString(request.getParameter(paramName));
params.put(paramName, paramVal);
}
return params;
}