Spring mvc @PathVariable

后端 未结 8 830
轮回少年
轮回少年 2020-11-27 11:41

Can you give me a brief explanation and a sample in using @PathVariable in spring mvc? Please include on how you type the url?
I\'m struggling in getting th

8条回答
  •  一整个雨季
    2020-11-27 11:50

    @PathVariable used to fetch the value from URL

    for example: To get some question

    www.stackoverflow.com/questions/19803731
    

    Here some question id is passed as a parameter in URL

    Now to fetch this value in controller all you have to do is just to pass @PathVariable in the method parameter

    @RequestMapping(value = " /questions/{questionId}", method=RequestMethod.GET)
        public String getQuestion(@PathVariable String questionId){
        //return question details
    }
    

提交回复
热议问题