I was working on a SpringBoot Rest Api.
I've a Comment entity. I just want to update comment's text. So I decided to use patchmapping.
I'm beginner on SpringBoot. I'm learning by the training. My plan was to find the comment by given Id. And update the text as a given String parameter.
When I use this controller with @RequestBody. And send a String via postman.
@PatchMapping("/updateStatus/{id}")
public ResponseEntity<CommentDto> updateTheUserStatus(@PathVariable Long id, @RequestBody String text){
return ResponseEntity.ok(commentService.changeStatus(id, text));
}
The Postman gives 500 Internal Error. But in the Database the text field is changing as I want.
{
"timestamp": "2022-04-13T08:17:13.615+00:00",
"status": 500,
"error": "Internal Server Error",
"path": "/v1/api/comment/updateStatus/4"
}
When I use this controller with @RequestParam Postman Gives 400 Bad Request and nothing is changing.
@PatchMapping("/updateStatusMe/{id}")
public @ResponseBody ResponseEntity<CommentDto> updateTheUserStatus1(@PathVariable Long id, @RequestParam String text){
return ResponseEntity.ok(commentService.changeStatus(id, text));
}
{
"timestamp": "2022-04-13T08:19:41.391+00:00",
"status": 400,
"error": "Bad Request",
"path": "/v1/api/comment/updateStatusMe/4"
}
I know that probably I'm totally wrong. But I'm asking this question for you to learn what am I missing. Thank you for your help!