SpringBoot中@Controller和@ResponseBody的区别

1,@Controller表明该类所有的方法返回页面路径,但是在方法上加了@ResponseBody后,该方法返回的是数据。
2,@RestController则相当于@Controller和@ResponseBody同时使用的效果,返回的也是数据,不是界面
3,如果我们还想返回界面可以使用ModelAndView方法

	@RequestMapping("/")
	public ModelAndView index(){
		ModelAndView  model = new ModelAndView();
		model.setViewName("/xxx")//界面路径
		return  model;

}

猜你喜欢

转载自blog.csdn.net/lbscsdn/article/details/82811439