gpt4 book ai didi

java - 无法映射正则表达式 - java.lang.IllegalArgumentException : The number of capturing groups in the pattern segment

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:13:12 25 4
gpt4 key购买 nike

我在我的 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...
}

但是,当我执行以下 HTTP 请求时 -/ajax/comments/post/ad1374659405664 我得到异常:

org.springframework.web.util.NestedServletException: Request processing failed; 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. Use non-capturing groups instead.

Google 没有给出那么多结果,这很奇怪,因为当我检查正则表达式时 ([vpa]|广告)\d+http://regexpal.com/它正确匹配所有内容。我做错了什么?

最佳答案

错误消息中已说明一切:改用非捕获组

(?:[apv]|ad)\\d+

参见 http://www.regular-expressions.info/brackets.html了解更多详情。

关于java - 无法映射正则表达式 - java.lang.IllegalArgumentException : The number of capturing groups in the pattern segment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20323848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com