我试图在我的 MVC 应用程序中构建一个干净的 URL 映射,我发现了很多常见的 URL,例如:
/SITE/{city}-{language}/user/{userId}
@RequestMapping(value = "/{city}-{language}/user/{userId}",
method = RequestMethod.GET)
public String user(@PathVariable String city,
@PathVariable String language,
@PathVariable String userId,
Model model) {}
/SITE/{city}-{language}/comment/{userId}-{commentId}
@RequestMapping(value = "/{city}-{language}/comment/{userId}-{commentId}",
method = RequestMethod.GET)
public String comment(@PathVariable String city,
@PathVariable String language,
@PathVariable String userId,
@PathVariable String commentId,
Model model) {}
有没有办法自动将城市和语言自动绑定到模型而不是过滤器的@PathVariable,我认为它可以减少@RequestMapping 函数参数的数量。