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
傳參數為獲取到的參數
?