有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java HTTP 500作为使用Spring控制器对HTTP Post请求的响应

我想在Post请求之后响应我的Json对象,但当我这样做时,我有一个内部服务器HTTP 500


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.beans.*;
import com.google.gson.JsonObject;

import programm.Manager;

@Controller

public class StudentRegistrationController {
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public StudentRegistrationReply registerStudent(@RequestBody Student student) {
        JsonObject t;
        StudentRegistrationReply stdregreply = new StudentRegistrationReply();
        StudentRegistration.getInstance().add(student);
        //Manager m = new Manager();
        t = Manager.solvingProcess(student.getContext(), student.getFilename());
        stdregreply.setSolution(t);
        return stdregreply;
    }

}

在Manager中调用该方法是没有问题的—它会做它应该做的一切。但在邮递员,例如,我得到了一个HTTP 500,我不明白为什么

{
    "timestamp": "2020-09-10T06:28:21.159+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "message": "",
    "path": "/"
}

有人有主意吗?我的管理器类只将字符串格式化为JSONObject,里面有JSONArray,一切正常


共 (1) 个答案

  1. # 1 楼答案

    我解决了这个问题。问题是我使用了谷歌的JSON。gson和httpresponse不能使用它。我将JSON从简单更改为JSON。json,一切正常