通过网络控制器服务休息电话?
Serving Rest calls through web controller?
可以使用常规 spring 网络控制器 映射到 restful 请求,还是我需要创建明确单独的 @Restful
控制器
对于相同的 ?
问这个问题的原因我有现有的 Web 控制器和其中的几个方法(我想映射到休息请求)已经以 json 形式返回数据
我理解最好将它们分开以使其模块化和可读,但我仍然想知道使用现有的 Web 控制器作为其余控制器在技术上是否可行?
来自@RestController
的docs
A convenience annotation that is itself annotated with @Controller and @ResponseBody.
Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default.
所以 @RestController
你得到正常的 Spring @Controller + @ResponseBody
。
你绝对可以使用 @Controller
作为你的 Restful api 但是你也需要明确使用 @ResponseBody
进行 Model/Entity 转换。
可以使用常规 spring 网络控制器 映射到 restful 请求,还是我需要创建明确单独的 @Restful
控制器
对于相同的 ?
问这个问题的原因我有现有的 Web 控制器和其中的几个方法(我想映射到休息请求)已经以 json 形式返回数据
我理解最好将它们分开以使其模块化和可读,但我仍然想知道使用现有的 Web 控制器作为其余控制器在技术上是否可行?
来自@RestController
的docs
A convenience annotation that is itself annotated with @Controller and @ResponseBody. Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default.
所以 @RestController
你得到正常的 Spring @Controller + @ResponseBody
。
你绝对可以使用 @Controller
作为你的 Restful api 但是你也需要明确使用 @ResponseBody
进行 Model/Entity 转换。