使用Groovy / Java
在三个封装的地图中获取值的最佳方法是什么?这是一个例子:
locations {
apache {
RewriteRule {
source = '^/apache(.*)$'
dest = 'http://192.x.x.x:8000/apache$1'
}
}
tomcat {
RewriteRule {
source = '^/tomcat/(.*)$'
dest = 'http://192.x.x.x:8000/tomcat/media/$1'
}
}
}
我想找到locations.x.RewriteRule.source
这是我的解决方案: 但我正在寻找更容易和更有效的东西
public boolean isSourceMatchURI(String uri) {
boolean result = false
locations.each {
location, rules ->
(rules as Map).each { rewriteRule, values ->
java.util.regex.Matcher matcher = (uri =~ (values as Map).source)
if (matcher.matches())
result = matcher.matches()
println((values as Map).source)
}
}
return result
}