2019独角兽企业重金招聘Python工程师标准>>>
1.获取连接中的参数,使用倒的关键词@PathVariable
@RestController public class HelloController {@RequestMapping(value = "/hello/{id}",method = RequestMethod.GET)public String index(@PathVariable("id") Integer id){return "id="+id;}}
启动项目访问,成功获取到id
也可以把id放在/hello前面
public class HelloController {@RequestMapping(value = "/{id}/hello",method = RequestMethod.GET)public String index(@PathVariable("id") Integer id){return "id="+id;}}
2.传统的问号(?id=110)传值,设置id可以不传默认值为0,使用倒的关键词@RequestParam
public class HelloController {@RequestMapping(value = "/hello",method = RequestMethod.GET)public String index(@RequestParam(value = "id" ,required = false, defaultValue = "0") Integer id){return "id="+id;}}
不传参数默认为0
传参数为获取到的参数