Spring mvc @PathVariable

后端 未结 8 829
轮回少年
轮回少年 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 12:05

    Annotation which indicates that a method parameter should be bound to a URI template variable. Supported for RequestMapping annotated handler methods.

    @RequestMapping(value = "/download/{documentId}", method = RequestMethod.GET)
    public ModelAndView download(@PathVariable int documentId) {
        ModelAndView mav = new ModelAndView();
        Document document =  documentService.fileDownload(documentId);
    
        mav.addObject("downloadDocument", document);
        mav.setViewName("download");
    
        return mav;
    }
    

提交回复
热议问题