欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

@[email protected]@[email protected]

程序员文章站 2022-03-14 19:05:44
...

@PathVariable

1.单参数实例,代码如下:

@RequestMapping("/path/{result}")
    public String testPathVariable(@PathVariable String result){
        return result;
    }

访问url:http://localhost:8080/path/resultdemo

@[email protected]@[email protected]

取路劲/path/后的值。

2.多参数示例

@RequestMapping("/pathTwo/{result}/{other}")
    public String testMulPathVariable(@PathVariable("result") String result,@PathVariable("other") String other){
        return result+"--"+other;
    }

@[email protected]@[email protected]

 

@PathParam

1.代码示例:

@RequestMapping("/pathParam")
    public String testPathParam(@PathParam("result") String result){
        return result;
    }

访问url: http://localhost:8080/pathParam?result=10086

@[email protected]@[email protected]

多参数示例与@PathVariable差不多

 

 

@RequestParam

代码实例:

@RequestMapping("/requestParam")
     public String testRequestParam(@RequestParam("result") String result){
        return result;
    }

 

访问url: http://localhost:8080/requestParam?result=100

@[email protected]@[email protected]

此处用法与 @PathParam相似

 

 

@RequestBody

用来传json数据,代码实例:

@RequestMapping("/requestBody")
     public String testRequestBody(@RequestBody String result){
        return result;
    }

用postman请求url:http://localhost:8080/requestBody?result=100 (result不是必须此处用来区别传入的值)

发送请求

@[email protected]@[email protected]

响应结果:

@[email protected]@[email protected]

 

相关标签: 注解