标签:
@RequestMapping(value="/{id}/{name}", method=RequestMethod.GET) public ModelAndView getUrlVariable(@PathVariable int id, @PathVariable String name){ ModelAndView mav = new ModelAndView(); mav.setViewName("list"); List<String> list = new ArrayList<String>(); list.add(id+""); list.add(name); mav.addObject("list", list); return mav; }
在参数中用标注,注明变量来自路径变量,如果路径变量和定义的变量名字不一样,需要指定路径变量和参数变量之间的映射关系,@PathVariable(“username”) String name
若对url进行限定,可以用正则表达式,如value="/{id:\\d+}"
标签:
原文地址:http://www.cnblogs.com/hpustudent/p/4318625.html