我想做的是为我的第二个参数传递一个正则表达式。例如:
- .*\\.txt
- .*2010.*\\.txt
@RequestMapping(value = "/filesCleanUp/{confParamName}/{pattern}", method = RequestMethod.GET)
public ResponseEntity<String> doFilesCleanUp(@PathVariable("confParamName") String confParamName,
@PathVariable("pattern") String pattern)
这就是我调用服务的方式:
- /filesCleanUp/param1/.*\\.txt
- /filesCleanUp/param1/.*2010.*\\.txt
但它不起作用,无法从 URL 中正确检索模式。对于第一个,我得到“.*\\”,对于第二个,我得到“.*2010.*\\”
我用其他值做了其他测试:
在 URL 中写入的模式:\(.*l
我得到:\(在 URL 中写入的模式:(2\.[0-3]))
我得到:(2\
通常它会弄乱 * 或 .
我确定这没什么,但我找不到。我想要的是得到我写的确切模式
谢谢你的帮助
最佳答案
如果你真的想这样传递参数(我强烈不推荐)请引用 http://perishablepress.com/how-to-write-valid-url-query-string-parameters/
否则编码并发布它们并在服务器端解码。
关于java - 在我的 REST 网络服务中将正则表达式作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13882362/