The method below fails with "PatternSyntaxException: Unclosed counted closure near index ... "
@RequestMapping(value ="/{id:[0-9|a-z]{15}}")
public View view(@PathVariable final String id) {
...
}
Looks like the pattern mat开发者_运维百科cher is trimming too much off the the string and losing the last }.
Does anyone know a work around to this bug? I'm having to drop the qualifier to "/{id:[0-9|a-z]+}" - which frankly suck!
Here's a solution. It's butt-ugly, but it's equivalent to what you'd like to have:
@RequestMapping(value = "/{id:[0-9a-z][0-9a-z][0-9a-z][0-9a-z]" +
"[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]" +
"[0-9a-z][0-9a-z][0-9a-z][0-9a-z]}") // 15 repetitions of [0-9a-z]
If that's the only way to get what you need, you might as well use this monster.
I don't think there are any good workarounds for this case except for manual validation. After all, {name:regexp}
syntax was introduced for solving ambiguities between mappings rather than for validation.
@Valid
on @PathVariable
s could be a solution, but it's promised only in Spring 3.1 (SPR-6380).
Also feel free to report this bug in Spring JIRA, although I don't expect them to fix it quickly since path variable handling code is already a mess.
精彩评论