Search code examples
javaspring-boothttp-postspring-restcontrollerhttp-put

PUT and POST - same parameter but bad request for PUT


I have Post method and Put method for requestMapping("projects").

@PutMapping
public ResponseEntity<ResultDomain> updateProjet(@RequestParam String projectJSON,
        @RequestParam MultipartFile image, @RequestParam(required = false) MultipartFile image1,
        @RequestParam(required = false) MultipartFile image2) throws Exception {
}

@PostMapping
public ResponseEntity<ResultDomain> addProjet(@RequestParam String projectJSON, @RequestParam MultipartFile image,
        @RequestParam(required = false) MultipartFile image1, @RequestParam(required = false) MultipartFile image2)
        throws Exception {
}

These 2 method have exactly the same parameter. When i request for POST, I have no problem with it. But when i request for PUT, it will return bad request. Is there any restriction for PUT method?

POSTMAN RESULT:

POST METHOD enter image description here

PUT METHOD enter image description here

Please help. Thanks in advance


Solution

  • Finally, I'm able to solve it by replace @RequestParam String projectJSON to @RequestPart String projectJSON. Still don't know why though..can anyone explain? Thanks for the kind answer..appreciated it