【问题标题】:Spring boot Regex to catch all routesSpring Boot Regex 捕获所有路由
【发布时间】:2020-12-03 05:51:35
【问题描述】:

参考Spring catch all route for index.html,我正在尝试使用正则表达式"/**/{spring:\\w+}"来捕获所有路线。但我得到了错误:

标记错误:java.util.regex.PatternSyntaxException,在索引 2 处悬空元字符“*”

当我通过"/\\*\\*/{spring:\\w+}" 修复此问题时,我的正则表达式无法捕捉路线。

请求相关指导。

【问题讨论】:

    标签: regex spring spring-boot regex-group


    【解决方案1】:

    如方法文档中所述:

    允许使用“/static/**”或“/css/{filename:\w+\.css}”等模式。有关语法的更多详细信息,请参阅 AntPathMatcher。

    见AntPathMatcher。我认为"/**/{spring:\\w+}" 至少需要更改为"/**/{spring:\w+}"

    【讨论】:

    • 你是对的。但至少这匹配:java boolean b = new AntPathMatcher().match("/**/{spring:\\w+}", "/foo/bar"); Assertions.assertTrue(b);
    猜你喜欢
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    • 2016-02-11
    • 1970-01-01
    • 2021-08-13
    相关资源
    最近更新 更多