我试图找到如何在 Spring 中编写以从 REST 客户端发布 JSON。例如,我写道:
@RequestMapping(value = "/{userId}/add", method = RequestMethod.POST, headers = {"content-type=application/json"})
@ResponseBody
public Map<String, String> saveUser(@RequestBody User user, BindingResult result) {
Map<String, String> jsonResponse = new HashMap<String, String>();
if (result.hasErrors()) {
jsonResponse.put("Message", "Can't add the user");
jsonResponse.put("Code", "401");
return jsonResponse;
}
userService.addUser(user);
jsonResponse.put("Message", "Success add User");
jsonResponse.put("Code", "200");
return jsonResponse;
}
最终从 Firefox REST 客户端对其进行了测试。但我看到了 404 错误。我究竟做错了什么?感谢您的帮助。