SpringMVC中GET請求類型接收參數的兩種方式

1, @PathVariable 方式接收URI參數。

URI如: http://localhost:8080/MyApp/123/Jack/ 
 

@GetMapping("user/{userId}/{userName}")
public String printMessage1(@PathVariable("userId") String id,@PathVariable("userName") String name) {

}

 

2,@RequestParam的方式接收URI參數。

URI如: http://localhost:8080/MyApp?date=12-05-2013

@GetMapping
public String printMessage1(@RequestParam("date") String theDate) {

}

 

ps:@RequestBody不屬於GET的接收參數方式。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章