spring mvc @PathVariable綁定URI模板變量值

@PathVariable綁定URI模板變量值

@PathVariable用於將請求URL中的模板變量映射到功能處理方法的參數上。

@RequestMapping(value="/users/{userId}/topics/{topicId}")  
public String test(  
       @PathVariable(value="userId") int userId,   
       @PathVariable(value="topicId") int topicId) 

如請求的URL爲“控制器URL/users/123/topics/456”,則自動將URL中模板變量{userId}和{topicId}綁定到通過@PathVariable註解的同名參數上,即入參後userId=123、topicId=456。代碼在PathVariableTypeController中。

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