What is the best way to return different types of ResponseEntity in Spring MVC or Spring-Boot

后端 未结 12 1502
南旧
南旧 2020-12-07 09:15

I have written simple rest application using Spring MVC 4 (or Spring-Boot). Within the controller I have return ResponseEntity. But in some cases I want to give

12条回答
  •  悲&欢浪女
    2020-12-07 09:42

    Note: if you upgrade from spring boot 1 to spring boot 2 there is a ResponseStatusException which has a Http error code and a description.

    So, you can effectively use generics they way it is intended.

    The only case which is a bit challenging for me, is the response type for a status 204 (ok with no body). I tend to mark those methods as ResponseEntity, because ResponseEntity is less predictive.

提交回复
热议问题