根据url获取URL的信息,可以通过springframework的工具类UriComponents
String url ="http://192.168.10.211:4000/child/portal/3?id=45";
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(url) .build();
1.获取接口路径:
uriComponents.getPath();
返回:/child/portal/3
2.获取端口
uriComponents.getPort()
返回:4000
3.获取ip
uriComponents.getHost()
返回:192.168.10.211
4.获取协议
uriComponents.getScheme()
返回:http
5.获取路径的名称(路径名称,根据斜杠隔开)
uriComponents.getPathSegments();
返回:["child","portal","3"]
6.获取查询参数:
uriComponents.getQueryParams();
返回:queryParams:{"id":["45"]}