【SpringMVC(六)】@RestController 与 @Controller 区别

微言记

关注

阅读 174

2022-11-11


其实很简单,打开@RestController注解即可:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {

/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
* @return the suggested component name, if any
* @since 4.0.1
*/
String value() default "";

}

可以看到,只是比@Controller多了一个@ResponseBody。

@ResponseBody表示返回结果是json,与返回ModelAndView相对,一般用于后端的api服务。

精彩评论(0)

0 0 举报