如何知道URL是否与特定PATH匹配

问题描述 投票:-1回答:1

我试图在Java过滤器中执行一些逻辑,具体取决于请求URL是否与特定PATH匹配。我们想要使用类似Java的PathMatcher而不使用Regex。另外,要求明确声明不使用Spring,因此spring的PathMatcher不是一个选项。

例如,给出以下URL: http://localhost:8080/base_path/customer/ {PARAM_VAL1} /顺序/ {PARAM_VAL2}

我正在寻找导致IF产生真实的东西:

PathMatcher pm = new SomeURLPathMatcherImp("/base_path/customer/*/order/*");

myURI = "/base_path/customer/customer001/order/98536"

if ( pm. matches(myURI) ){
    myFunction();
}

注意:我使用PathMatcher来描述问题。我想知道是否有除Spring以外的任何API库来执行类似于Java的FileSystem类实现的URL PATH匹配

java url path
1个回答
0
投票
PathMatcher pm = FileSystems.getDefault().getPathMatcher("glob:/base_path/customer/*/order/*");

System.out.println(pm.matches(Paths.get("/base_path/customer/customer001/order/98536")));  // true
System.out.println(pm.matches(Paths.get("/base_path/customer/customer001/order")));        // false
© www.soinside.com 2019 - 2024. All rights reserved.