我有密码
@RequestMapping(value = "/graph", method = RequestMethod.POST)
@ResponseBody
public HttpServletResponse graphImport() {
JSONParser parser = new JSONParser();
GraphJson savedGraph = new GraphJson();
try {
Object obj = parser.parse(new FileReader("graph.json"));
JSONObject jsonObject = (JSONObject) obj;
GraphJson graph = new GraphJson();
graph.setSource(jsonObject.toString());
session.save(graph);
savedGraph = session.get(GraphJson.class, 1);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println("CREATED");
return resp;
//return "id :" + savedGraph.getId() + ", " + savedGraph.getSource();
}
当我使用
curl http://localhost:8080/graph
当我向该URL发送一个POST请求时,我需要返回状态201,用于创建和方法POST。在这方面需要一些帮助。谢谢.
我用过
@ResponseStatus(HttpStatus.CREATED)
在@requestmapping
和@responsecode
之间运行,当我发送它返回的一个post请求时,它起作用
代码201已创建
记住在HttpStatus.
之后创建的可能是另一个代码。