Spring mvc @PathVariable

后端 未结 8 859
轮回少年
轮回少年 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:58

    Have a look at the below code snippet.

    @RequestMapping(value="/Add/{type}")
    public ModelAndView addForm(@PathVariable String type ){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("addContent");
        modelAndView.addObject("typelist",contentPropertyDAO.getType() );
        modelAndView.addObject("property",contentPropertyDAO.get(type,0) );
        return modelAndView;
    }
    

    Hope it helps in constructing your code.

提交回复
热议问题