本文主要是介绍SpringBoot中注解@RestController | @ResponseBody | @Controller,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
@ResponseBody
可以修饰类和方法
@Controller
和 @RestController
只能修饰类
@RestController
告诉Spring,帮我们管理这个代码,我们后续访问时,才能访问到
@RequestMapping
路由映射,可以修饰方法,也可以修饰类
访问地址:类的路径+方法的路径
支持get和post
@RequestMapping("/hello")
@RestController
public class HelloController {@RequestMapping("/hi")public String sayHi(){return "hi";}
}
使用method,限制请求方式
(注解没有写属性名,默认是value)
@RequestMapping(value = "/hello",method = RequestMethod.GET)public String sayHello(){return "hello";}
这篇关于SpringBoot中注解@RestController | @ResponseBody | @Controller的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!