1. 三者的关系图
2. 作用
@RequestMapping、@PostMapping、@GetMapping均为映射请求路径,可作用于类或方法上。当作用于类时,是该类中所有响应请求方法地址的父路径。
3. 示例
@RequestMapping("/test") //test即父路径
public class test {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
// @GetMapping("/hello")
@ResponseBody // 将返回的java对象转为json格式的数据
public String hello() {
return "hello world !";
}
}
访问路径:http://localhost:8080/test/hello (切记不要忘记“test”哦!)
温馨提示:读者可自行去了解POST请求和GET请求的区别
可参考:https://www.cnblogs.com/logsharing/p/8448446.html