第一次使用:@RestController时,一直返回字符串,未跳转至指定页面。
原因分析:
@RestController注解由@Controller+@ResponseBody两个注解派生而来,
@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 (or empty String otherwise)
* @since 4.0.1
*/
@AliasFor(annotation = Controller.class)
String value() default "";
}
解决方法:
@ResetController修改为@Controller即可跳转页面。
提醒:
@Responsebody后,返回结果直接写入HTTP response body中,不会被解析为跳转路径。
使用@RestController返回json数据就不需要在方法前面加@ResponseBody注解了。