有没有办法发送参数,如" https://jira.springsource.org/browse/SPR-6164"在@PathVariable中作为URI路径的一部分...在Spring Web MVC中
@RequestMapping(value = "/Details/{Emailaddress}/{URL}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Status Details(@PathVariable("Emailaddress") String Emailaddress,
@PathVariable("URL") String URL) {
try {
bankingData.callingmethod(Emailaddress,URL);
return new Status(1, "Details added !");
} catch (Exception e) {
// e.printStackTrace();
return new Status(0, e.toString());
}
}
错误:请求的资源不可用
答案 0 :(得分:4)
但是你必须正确编码。使用URLEncoder.encode()
执行此操作:
String url =
"http://server/Details/"+URLEncoder.encode("http://myserver/mypath/to/url/", "UTF-8");
构造URL时,必须在客户端执行此代码。编码必须同时应用于pat元素和查询参数。
答案 1 :(得分:1)
尝试在您的方法中像url
这样写{URL:.+}
:
@RequestMapping(value = "/Details/{Emailaddress}/{URL:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public Status Details(@PathVariable("Emailaddress") String Emailaddress,
@PathVariable("URL") String URL) {
点.
的requestParameter被截断。