Controller的使用
@RestController
用来处理http请求,Spring4之后新加的注解,原来返回json需要@Controller
配合@ResponseBody
实现,现在只需要一个@RestController
即可@RequestMapping
配置URL映射,限定请求方法、请求参数、请求头
a. 在一个类的函数上面加上@RequestMapping(value = "/",method = RequestMethod.GET)
就是只能通过GET方式访问http://127.0.0.1:8088/
``` @RequestMapping(value = "/",method = RequestMethod.GET) public String index(){ return "OK"; } ```
b. 在一个类的函数上面加上
@RequestMapping(value = "/"
就可以通过GET或者POST方式访问http://127.0.0.1:8088/index
``` @RequestMapping(value = "/index") public String index(){ return "OK"; } ```
c. 在一