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

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐