我的 Controller 映射:
@RequestMapping(value = "{objectId}/{objectName: [a-zA-Z-]+}", method = GET)
public String getObjects(@PathVariable Integer objectId, Model model) { ... }
@RequestMapping(value = "{objectId}/{objectName: [a-zA-Z-]+}_{category}", method = GET)
public String getObjectsForCategories(@PathVariable Integer objectId,
@PathVariable String category,
Model model) { ... }
我正在访问的网址:
Spring 无法找到处理程序并提示找不到 HTTP 请求的映射。
最佳答案
The
@RequestMapping
annotation supports the use of regular expressions in URI template variables. The syntax is{varName:regex}
where the first part defines the variable name and the second - the regular expression.
因此,您应该删除 :
和 regex
之间的空格,如下所示:
@RequestMapping(value = "{objectId}/{objectName:[a-zA-Z-]+}", method = GET)
^ Space is removed
关于java - Spring MVC Controller 映射正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37329238/