2
给定的Spring MVC控制器上的以下请求映射:如何配置Spring MVC @PathVariables接受包含Dash的字符串?
@RequestMapping(method=GET, value="https://stackoverflow.com/users/{name}")
ModelAndView findUser(@PathVariable String name) {
...
}
我怎样才能使它接受它一个破折号@PathVariable
?
下面的作品,fred
传递作为名称:
GET /users/fred
但是以下不工作,传递null
替代名称:
GET /users/u-fred
我会在感激的建议如何定义@PathVariable
以便它可以接受虚线字符串,例如u-fred
。
谢谢。
只是好奇......你有一些'@ InitBinder`会导致这个问题吗?一个带破折号的字符串对我来说很好,我在我的项目中使用它很多。 – limc 2011-01-28 23:57:12
如果不使用URL编码,则虚线和下划线是完全合法的字符。我想你可以做{foo} - {bar}并有2个参数,但这完全没有必要。 – hisdrewness 2011-01-29 04:43:06