我有密码

@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();
}

当我使用
卷曲http://localhost:8080/graph
当我向那个url发送一个post请求时,我需要为created和methodpost返回状态201。需要帮助。谢谢您。

最佳答案

我用过

@ResponseStatus(HttpStatus.CREATED)

@RequestMapping@ResponseCode之间,当我发送一个post请求时它工作了
代码201已创建
记住CREATED后面的HttpStatus.可能是另一个代码。

10-04 10:21