spring boot 使用@Controller与@RestController的差别

@RestController 的作用

  • @RestController 是一个组合注解时@Controller和@ResponseBody的组合,在spring boot中,使用了@RestController注解时,页面的视图解析器就起不到作用,在页面上只是会返回return 里的字符串而非路径所以根本无法到jsp或者html页面上,如,return ”index”,则会在页面上只看见index,而不是到index.html 页面上
  • 使用@Controller 和视图解析器则可以成功的到达想要的界面,如果需要换回json或则自定义的页面,加上@ResponseBody即可实现

猜你喜欢

转载自blog.csdn.net/qq_40674814/article/details/88774903