Why does @RepositoryRestController do not have @ResponseBody annotation like @RestController?

梦想的初衷 提交于 2019-12-11 09:54:40

问题


I'm using Spring-data-rest and wondering if there is a reason behind the fact that @RestController also has @ResponseBody but @RepositoryRestController has not.


回答1:


All controllers in Spring Data REST using that annotation return a ResponseEntity<T> anyway, so that technically @ResponseBody is not needed.

We generally prefer ResponseEntity as return type for two reasons:

  1. In controller methods serving REST requests, you usually want to control details of the response (headers, the status code etc.) for which ResponseEntity is exactly the type for.
  2. Spring MVC detects ResponseEntity and thus we don't the additional annotation.

I'm not sure we can actually change that, as despite the name of the annotation, there could be implementations out there that still use view resolution. If you still think, it's a good idea, feel free to raise a ticket in our JIRA.



来源:https://stackoverflow.com/questions/33712303/why-does-repositoryrestcontroller-do-not-have-responsebody-annotation-like-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!