0

In Restful API, what is the difference between ResponseEntity and ResponseEntity<?>?

When should we use one or the other? This is my code:

@PutMapping
public ResponseEntity<?> updateArticle(@PathVariable("slug") String slug,
                                       @AuthenticationPrincipal User user,
                                       @Valid @RequestBody UpdateArticleParam updateArticleParam) {
    return articleRepository.findBySlug(slug).map(article -> {
        if (!AuthorizationService.canWriteArticle(user, article)) {
            throw new NoAuthorizationException();
        }
        article.update(
            updateArticleParam.getTitle(),
            updateArticleParam.getDescription(),
            updateArticleParam.getBody());
        articleRepository.save(article);
        return ResponseEntity.ok(articleResponse(articleQueryService.findBySlug(slug, user).get()));
    }).orElseThrow(ResourceNotFoundException::new);
}

@DeleteMapping
public ResponseEntity deleteArticle(@PathVariable("slug") String slug,
                                    @AuthenticationPrincipal User user) {
    return articleRepository.findBySlug(slug).map(article -> {
        if (!AuthorizationService.canWriteArticle(user, article)) {
            throw new NoAuthorizationException();
        }
        articleRepository.remove(article);
        return ResponseEntity.noContent().build();
    }).orElseThrow(ResourceNotFoundException::new);
}
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • SO is generally an English-only site. Suggest (if possible) you stick to that since you'll be more likely to get an answer. I've translated as best I can, you may want to check... – paxdiablo Sep 27 '19 at 10:05
  • Possible duplicate of [What does (angle brackets) mean in Java?](https://stackoverflow.com/questions/6607550/what-does-t-angle-brackets-mean-in-java) – Raedwald Sep 27 '19 at 10:57
  • See [What is a raw type and why shouldn't we use it?](https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it). – Raedwald Sep 27 '19 at 11:00

0 Answers0