@PathVariable與@RequestParam的差別
首先呢這二個注解都是接收參數使用的,下面來看一下它們的差別。
@PathVariable注解
@RequestMapping(value ={“/hello/{id}”,”{id}/hi”},method = RequestMethod.GET)
//@GetMapping(“/hello/{id}”)
public String hello(@PathVariable(“id”) Integer id){
return “id:”+id;
}
位址欄參數如下,後面直接跟id值就可以。
http://localhost:8888/hello/66
-
return "id:"+id;
-
//return "index";
-
}