Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring请求映射到特定路径变量值的不同方法_Java_Spring_Spring Mvc_Controller - Fatal编程技术网

Java Spring请求映射到特定路径变量值的不同方法

Java Spring请求映射到特定路径变量值的不同方法,java,spring,spring-mvc,controller,Java,Spring,Spring Mvc,Controller,它仍在将/authors/*/author properties映射到路径变量值为“*”的getAuthorProperties方法,查看这是否有效 @RequestMapping(value = "/*/author-properties", method = RequestMethod.GET) 您可以使用正则表达式约束单个作者的映射,例如: @RequestMapping(value = "/{id:.*}/author-properties", method = RequestMeth

它仍在将
/authors/*/author properties
映射到路径变量值为“*”的getAuthorProperties方法,查看这是否有效

@RequestMapping(value = "/*/author-properties", method = RequestMethod.GET)

您可以使用正则表达式约束单个作者的映射,例如:

@RequestMapping(value = "/{id:.*}/author-properties", method = RequestMethod.GET)
这将只匹配作者ID为数字的URL

对于所有作者属性的请求,您可以使用:

@RequestMapping("/{authorId:\\d+}/author-properties")
public String authorProperties(@PathVariable String authorId) {}
howewer
*
具有特殊含义,因此它也将匹配
/foo/author属性。要解决此问题,您可以使用以下方法:

@RequestMapping("/*/author-properties")
public String allProperties() { }

如果获取所有作者的authorProperty列表是常见的情况,那么我认为您应该创建如下URI:“/AuthorProperties”。否则,Bohuslav给出的答案就是您想要的。

当我将/*/author属性的方法保留在/{id}/author属性的方法之前时,它开始工作。那么这是一个合适的解决方案吗?我们能否始终将映射的处理顺序作为方法声明的顺序?
@RequestMapping("/*/author-properties")
public String allProperties() { }
@RequestMapping("/{all:\\*}/author-properties")
public String allProperties() { }