Spring MVC 3 RequestMapping with Regular Expression Quantifiers

The method described below is "PatternSyntaxException: Unblocked counted close next to index ..."

@RequestMapping(value ="/{id:[0-9|a-z]{15}}")
public View view(@PathVariable final String id) {
  ...
}

Pattern matching seems to cut the string too much and lose the last one.

Does anyone know about this error? I need to drop the qualifier on "/ {id: [0-9 | az] +}" - which frankly suck!

+3
source share
2 answers

I do not think that in this case there are no good workarounds other than manual verification. In the end, syntax {name:regexp}was introduced to resolve the ambiguities between comparisons, and not for verification.

@Valid on @PathVariable , Spring 3.1 (SPR-6380).

Spring JIRA, , , .

+5

. , , :

@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]

, , .

+5

Source: https://habr.com/ru/post/1793065/


All Articles