【发布时间】:2020-01-19 08:10:20
【问题描述】:
在我的 Springboot-Controller 中,我的 Requestmapping 方法应该支持灵活的子目录名称。为此,我喜欢使用真正的正则表达式。我已经测试了我的正则表达式,它在 SpringBoot 和 RequestMapping 之外工作正常,但是在 RequestMapping 之上它不起作用。
如果有任何 http-requests 进入
http://dir1 或 http://dir2
我的方法 getFile 应该被调用,但它没有。
@RequestMapping(value = "{reg:\\/(dir1|dir2)+}", method = RequestMethod.GET)
public void getFile(HttpServletResponse response, HttpServletRequest requ) throws IOException {
}
我的问题是如何做到这一点......
【问题讨论】:
-
我猜你想恢复方法内部的路径?因此,使用
@RequestMapping(value = "/{dir}", ...) public File getFile(@PathVariable("dir") String directory,...)之类的东西可能会更好 -
谢谢 Dirk(德语?)。我也认为我必须恢复方法内部的路径。当我写信给 Jayanthi 时,我正在寻找任何可以确认 RequestMapping 不支持通过正则表达式的多个路径值的文档行。
-
只要您的“目录”不包含“/”,您就可以将正则表达式与
@GetMapping("/{reg:[dir1|dir2]+}")等 PathVariable 结合使用
标签: regex spring-boot subdirectory request-mapping