I have a post method in my controller class to create an offer and i want to show response status of 201 i.e. created when hitting the api via postman. This can be achieved by two methods which are @ResponseStatus(HttpStatus.CREATED) and ResponseEntity. I wanted to know what is the difference between the two. I have put them in comments below.
@PostMapping("/offers")
**//@ResponseStatus(HttpStatus.CREATED)**
public ResponseEntity<Object> createOffer(@Valid @RequestBody Offer offer) {
Offer uoffer = offerService.createOffer(offer);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{jobTitle}").
buildAndExpand(uoffer.getJobTitle()).toUri();
**return ResponseEntity.created(location).build();**
}