我有一个带有两个参数 long 和 String 的 Spring 控制器:
@RequestMapping(value = "/webpage")
@Controller
public class WebpageContentController {
//...
@RequestMapping(value = "{webpageId}/{webpageAddress}", method = RequestMethod.GET)
public String contentWebpageById(@PathVariable long webpageId, @PathVariable String webpageAddress) {
System.out.println("webpageId=" + webpageId);
System.out.println("webpageAddress=" + webpageAddress);
//...
}
//...
如果我这样调用它:
http://localhost:8080/webarch/webpage/1/blahblah
一切皆好:
webpageId=1
webpageAddress=blahblah
但是如果我用斜杠传递字符串参数(在这种情况下是 URL 地址):
http://localhost:8080/webarch/webpage/1/https://en.wikipedia.org/wiki/Main_Page
我收到一个错误:
org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/webarch/webpage/1/https://en.wikipedia.org/wiki/Main_Page] in DispatcherServlet with name 'appServlet'
如何传递这样的参数?