您的位置:首页 > 产品设计 > UI/UE

@PathVariable、@RequestParam、@RequestBody的区别

2017-06-29 20:42 806 查看
一、@PathVariable的url是这样的:http://host:port/.../path/参数值 
http://127.0.0.1/xx/xx/deleteGroup/1
例如:

@RequestMapping(value = "deleteGroup/{id}", method= RequestMethod.GET)

public void deleteGroupById(@PathVariable Long Id) {

}

二、@RequestParam的url是这样的:http://host:port/.../path?参数名=参数值 
http://127.0.0.1/xx/xx/add?name=xx&years=xx
例如:

@RequestMapping(value = "/add", method = RequestMethod.POST) 

    public void add(@RequestParam("name") String name,  @RequestParam("years") int years){ 

    } 

三、@RequestBody的url是这样的:http://host:port/.../path但是得传入json对象的body。

@RequestMapping(value = "/add", method = RequestMethod.POST)

    public  void add(@RequestBody User user) {

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: