JSON发布到Spring Controller
2022-09-03 18:16:07
嗨,我从春季的Web服务开始,所以我正在尝试在春季+ JSON + Hibernate中开发小型应用程序。我有一些HTTP-POST问题。我创建了一个方法:
@RequestMapping(value="/workers/addNewWorker", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
@ResponseBody
public String addNewWorker(@RequestBody Test test) throws Exception {
String name = test.name;
return name;
}
我的模型测试看起来像这样:
public class Test implements Serializable {
private static final long serialVersionUID = -1764970284520387975L;
public String name;
public Test() {
}
}
通过POSTMAN,我只是发送JSON {“name”:“testName”},我总是得到错误;
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
我导入了杰克逊图书馆。我的 GET 方法工作正常。我不知道我做错了什么。我感谢任何建议。