[英]Can't map regular expression - java.lang.IllegalArgumentException: The number of capturing groups in the pattern segment
I have the following method defined in my controller:我在控制器中定义了以下方法:
@RequestMapping(value = "/ajax/comments/post/{contentId:([apv]|ad)\\d+}")
public @ResponseBody
ActionResult handlePostCommentRequest(HttpServletRequest request, Model model,
@PathVariable("contentId") String assetId,
@RequestParam(value = "nickName", required = false, defaultValue = "Anonyymi") String nickName,
@RequestParam(value = "text", required = false, defaultValue = "") String text,
@RequestParam(value = "createThread", required = false, defaultValue = "false") String createThread) {
// some code...
}
However, when I do the following HTTP request - /ajax/comments/post/ad1374659405664 I get exception:但是,当我执行以下 HTTP 请求时 - /ajax/comments/post/ad1374659405664 我得到异常:
org.springframework.web.util.NestedServletException: Request processing failed;
org.springframework.web.util.NestedServletException:请求处理失败; nested exception is java.lang.IllegalArgumentException: The number of capturing groups in the pattern segment (([apv]|ad)\\d+) does not match the number of URI template variables it defines, which can occur if capturing groups are used in a URI template regex.
嵌套异常是 java.lang.IllegalArgumentException: The number of capture group in the pattern segment (([apv]|ad)\\d+) 与它定义的 URI 模板变量数不匹配,如果在URI 模板正则表达式。 Use non-capturing groups instead.
请改用非捕获组。
Google doesn't give that much results and it is weird, because when I check the regex ([vpa]|ad)\\d+
in http://regexpal.com/ it matches everything correctly. Google 没有给出那么多结果,这很奇怪,因为当我检查http://regexpal.com/ 中的正则表达式
([vpa]|ad)\\d+
,它会正确匹配所有内容。 What am I doing wrong?我究竟做错了什么?
Everything is said in the error message: use non-capturing groups instead
错误消息中说明了一切:
use non-capturing groups instead
(?:[apv]|ad)\\d+
See http://www.regular-expressions.info/brackets.html for further details.有关更多详细信息,请参阅http://www.regular-expressions.info/brackets.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.