示例:
@PathVariable
获取url中所带的参数,如http://127.0.0.1:8081/girl/hello/say/12
@RequestMapping(value = "/say/{id}" ,method = RequestMethod.GET) public Integer say(@PathVariable("id") Integer id){ return id; }@RequestParam
获取url后所带的请求参数,如http://127.0.0.1:8081/girl/hello/say?id=12
@RequestMapping(value = "/say" ,method = RequestMethod.GET) public Integer say(@RequestParam(value = "id",required = false,defaultValue ="1") Integer myId){ return myId; }注:@RequestParam中‘required ’值表示时候可不传入,‘defaultValue ’值表示当不传入是的默认值,必须为String类型
@RequestMapping @RequestMapping(value = "/say" ,method = RequestMethod.GET)等价于
@GetMapping(value = "/say")