spring mvc匹配url并使用as变量

时间:2012-12-29 15:19:54

标签: java spring url spring-mvc

@RequestMapping(value = "/Foo/{id}/{friendlyUrl:*}", method = RequestMethod.GET)
public ModelAndView getFoo(@PathVariable final Long id, @PathVariable final String friendlyUrl, final Principal principal) {
/* then match friendlyUrl, 
 * if it doesn't match use redirect 
 * view to send to correct place*/
}

我使用asterix时我的ide会回来时出错?

1 个答案:

答案 0 :(得分:1)

如果您打算使用正则表达式进行匹配,那么我猜您想要的是

"/Foo/{id}/{friendlyUrl:.*}"

根据doc,模式必须为{varName:regex}