SpringBoot中最常用的【出参注解】
注解介绍
@Controller可以直接通过返回String跳转到jsp、ftl、html等模版页面。@Controller在方法上使用@ResponseBody可以返回实体。@RestController是@Controller和@ResponseBody的结合体,任何方法不再需要单独添加@ResponseBody注解。1
2
3
4
5
6
7
8
9
10
11
12
public class DemoController {
// xxxxxxxx
}
等价于
public class DemoController {
// xxxxxxxx
}@RestController只能返回String、Object、Json等实体对象,不能直接跳转jsp、ftl、html等模版页面。@RestController想跳转jsp、ftl、html等模版页面,只能用ModelAndView封装。1
2
3
4
5
6
7
8
public class DemoController {
public String toIndex(){
ModelAndView mv = new ModelAndView("index");
return mv;
}
}
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 学弟不想努力了!
评论











