我遇到了一个奇怪的问题。 这是我的 REST API 映射
@RequestMapping(
value = { "/{email}" },
method = RequestMethod.GET,
params = "time")
public void getEmail(
@PathVariable("email") final String sender,
@RequestParam(value = "time", required = true) final long time)
当我这样调用 API 时
/someone@someone.com?time=10
我观察到 sender
包含 someone@someone
而不是 someone@someone.com
。
当我这样给它的时候
@RequestMapping(
value = { "/{email:.+}" },
method = RequestMethod.GET,
params = "time")
public void getEmail(
@PathVariable("email") final String sender,
@RequestParam(value = "time", required = true) final long time)
我收到 406 错误。
我也试过了
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="useSuffixPatternMatch" value="false" />
</bean>
仍然没有帮助。 我做错了什么?
最佳答案
摘自 RequestMapping
JavaDoc:
@PathVariable annotated parameters (Servlet-only) for access to URI template values (i.e. /hotels/{hotel}). Variable values will be converted to the declared method argument type. By default, the URI template will match against the regular expression [^.]* (i.e. any character other than period), but this can be changed by specifying another regular expression, like so: /hotels/{hotel:\d+}. Additionally, @PathVariable can be used on a Map to gain access to all URI template variables.
您的第二个映射定义正确且有效。您可能没有正确测试它。
关于java - 包含 .com、.org 的路径变量在 REST API 中被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24197134/