【发布时间】:2014-08-03 12:43:11
【问题描述】:
我遇到了一个奇怪的问题。 这是我的 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>
仍然没有帮助。 我做错了什么?
【问题讨论】:
-
/{email}和@PathVariable("sender")?你确定命名? -
嗨,我更新了正确的名字
-
需要更多上下文。这些注释来自哪个库?
-
这些是 Spring MVC 注释......顺便说一句。我刚刚验证了这种行为。将检查问题可能出在哪里。
-
您会在 SO Spring MVC @PathVariable with dot (.) is getting truncated 的其他帖子中找到很多解释
标签: java rest path-variables