接口入参注解@PathVariable与@RequestParam

@RequestParam

@RequestMapping(value = "/test", method = {RequestMethod.POST, RequestMethod.GET})
public String test(@RequestParam("name") String name) {
System.out.println(name);
return name;
}

http://localhost:端口号/test?name=345

@PathVariable

 @RequestMapping(value = "/test/{name}", method = {RequestMethod.POST, RequestMethod.GET})
    public String test(@PathVariable("name") String name) {
        System.out.println(name);
        return name;
    }

localhost:22499/user/test/zhangsan

两个注解可以组合使用

 

posted @ 2023-05-06 14:20  皮军旗  阅读(35)  评论(0)    收藏  举报