1.注解@PathVariable和@RequestParam的区别
@RequestParam注解是获取静态URL传入的参数
@PathVariable是获取请求路径中的变量作为参数
如下例子:
@RestController
@RequestMapping(value="users")
public class UserController {
@RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
public Map<String, Object> list(@RequestParam Long user_id) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("user_id", user_id);
return map;
}
@RequestMapping(value = "/get_user/{user_id}", method = {RequestMethod.GET, RequestMethod.POST})
public Map<String, Object> get_user(@PathVariable Long user_id) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("user_id", user_id);
return map;
}
}
网友评论