导入:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
//工具类
//截取字符串信息
public String getParamByUrl(String url, String name) {
String params = url.substring(url.indexOf("?") + 1, url.length());
if (StringUtils.isNotBlank(params)) {
Map<String, String> split = Splitter.on("&").withKeyValueSeparator("=").split(params);
return split.get(name);
}
return "";
}
示例:
Eg链接:
获取utm_source参数:
String url="http://localhost:9090/?utm_source=eeee&utm_medium=email&utm_campaign=summer-sale"
getParamByUrl(url, "utm_source")