简体   繁体   English

无法映射正则表达式 - java.lang.IllegalArgumentException: 模式段中的捕获组数

[英]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.

相关问题 java.lang.IllegalArgumentException:无法解析参数编号:电话 - java.lang.IllegalArgumentException: can't parse argument number: Phone java.lang.IllegalArgumentException:地图大小(0)必须&gt; = 1 - java.lang.IllegalArgumentException: Map size (0) must be >= 1 java.lang.IllegalArgumentException:无法创建类的实例 - java.lang.IllegalArgumentException: Can't create an instance of class java.lang.IllegalArgumentException:不能有viewTypeCount <1 - java.lang.IllegalArgumentException: Can't have a viewTypeCount < 1 java.lang.IllegalArgumentException - java.lang.IllegalArgumentException java.lang.IllegalArgumentException - java.lang.IllegalArgumentException 正则表达式中的捕获组和模式拆分方法 - Capturing groups and Pattern split method in regular expression LocalDateTime 解析抛出“java.lang.IllegalArgumentException:未知模式字母:T” - LocalDateTime parsing throws “java.lang.IllegalArgumentException: Unknown pattern letter: T” Mongo java.lang.IllegalArgumentException:无法序列化类java.lang.Class - Mongo java.lang.IllegalArgumentException: can't serialize class java.lang.Class 格式化参数“” java.lang.IllegalArgumentException时发生异常:非法模式字符“ T” - Exception while formatting the parameter“ ”java.lang.IllegalArgumentException: Illegal pattern character 'T'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM