1

对于下面的代码,当我试图通过邮递员时,它仅在附加文件时工作正常。但是,当未附加文件时,它会引发内部服务器错误,它就在下面。但在我的情况下,如果文件没有附加,它也需要工作。提前致谢

@PostMapping("add")
public ResponseEntity<JSONObject> addProject(
    @RequestPart(required = false, value = "file")  MultipartFile file,
    @RequestPart(value = "jsonObject", required = false) JSONObject jsonObject) {
        JSONObject responseJsonObject = null;
        try {
            responseJsonObject = service.addProject(request, response, file, jsonObject);
      } catch (Exception e) {
        LOGGER.error("Error in addProject() method !!", e);
      }
      return new ResponseEntity<JSONObject>(responseJsonObject, HttpStatus.CREATED);
}

未附加文件时邮递员的响应:

<!doctype html>
<html lang="en">

<head>
    <title>HTTP Status 500 – Internal Server Error</title>
    <style type="text/css">
        body {
            font-family: Tahoma, Arial, sans-serif;
        }

        h1,
        h2,
        h3,
        b {
            color: white;
            background-color: #525D76;
        }

        h1 {
            font-size: 22px;
        }

        h2 {
            font-size: 16px;
        }

        h3 {
            font-size: 14px;
        }

        p {
            font-size: 12px;
        }

        a {
            color: black;
        }

        .line {
            height: 1px;
            background-color: #525D76;
            border: none;
        }
    </style>
</head>

<body>
    <h1>HTTP Status 500 – Internal Server Error</h1>
</body>

</html>
4

0 回答 0