Url 在路径变量中 spring restful 服务

Url in a path variable spring restful service

当我将电子邮件地址作为路径变量传递时,它抛出以下错误

    Console --> 2015-02-09 16:30:06,634 WARN  - GET request for "http://localhost:8181/abc/users/testabghtmail@gmail.com" resulted in 406 (Not Acceptable); invoking error handler
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 406 Not Acceptable
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
    at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:607)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:565)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:521)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:439)
    at RestClient.main(RestClient.java:35)

我尝试了很多案例,所以我终于找到了最后一个域的问题,比如 .com.org 是国际化的域。因此,如果我通过 "testabghtmail@gmail.dom" 而不是 "testabghtmail@gmail.com",它将完全正常工作。

我的密码是

@RequestMapping(value = "users/{emailId:.*}", method = RequestMethod.GET)
    public Object searchUser(@PathVariable("emailId") String emailId){
        logger.info("Inside search user --> emailId " + emailId);
        return userService.findUserByuserId(emailId);
}

我没有找到答案。我认为这是一个 http 规则,我们终于不能在参数中有域并且可以发出请求。

因此解决这个问题的方法是在 url 末尾传递一个斜杠,然后就可以了。

喜欢修改“http://localhost:8181/abc/users/testabghtmail@gmail.com/" with "http://localhost:8181/abc/users/testabghtmail@gmail.com”。多亏了 spring rest 架构,它会自动省略最后一个斜杠,你会得到 "testabghtmail@gmail.com" 作为参数值。

如果你们发现其他东西,请告诉我。