java – Spring-MVC PathVariable匹配正则表达式,不以word开头
作者:互联网
我希望将所有请求与一个不以’api’开头的PathVariable匹配.我在RequestMapping之后测试. spring可以匹配请求,但无法获得PathVariable的值.我怎么解决这个问题?
@RequestMapping(value = "/{name:(?!api).+}", method = RequestMethod.GET)
public void getNotApi(@PathVariable String name, HttpServletResponse response) {
...
}
我收到一些请求的消息,如localhost:8080 / resource.
错误500缺少URI模板变量& name&对于String类型的方法参数
解决方法:
@RequestMapping(value = "/{name:^(?!api).+}", method = RequestMethod.GET)
标签:java,spring-mvc,spring,request-mapping 来源: https://codeday.me/bug/20190627/1306987.html