java - 包含 .com、.org 的路径变量在 REST API 中被截断

标签 java rest path-variables

我遇到了一个奇怪的问题。 这是我的 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/

相关文章:

python - Django Rest框架,从其他模型数组创建模型

rest - 通过 REST API 添加/导入 Sharepoint 2013 WebPart

java - Spring REST API 为 pojo 注册日期转换器

java - 系统差异。 Java 中的 exit(0) 、 System.exit(-1)、 System.exit(1 )

java - 所需 bundle 的状态已解决而不是 Activity

linux - rest api 中的 curl 身份验证失败

RStudio 显示不同的 $PATH 变量

java - Playframework 2 作为 SOAP 服务器

java - 我是否也应该在 Java 中更新双向关系?

rest - 如何在AngularJS $ resource中使用路径变量而不是请求参数