class UrlUtil {
public static void main(String[] args) throws UnsupportedEncodingException {
String res = getURLEncoderString("/books/测试分享/page/依赖的第三方系统分享");
System.out.println(res);
res = getURLDecoderString(res);
System.out.println(res);
}
private final static String ENCODE = "UTF-8";
/**
* URL 解码
*
* @param str
* @return String
*/
public static String getURLDecoderString(String str) throws UnsupportedEncodingException {
if (StringUtils.isNotBlank(str)) {
return java.net.URLDecoder.decode(str, ENCODE);
}
return "";
}
/**
* URL 转码
*
* @param str
* @return String
*/
public static String getURLEncoderString(String str) throws UnsupportedEncodingException {
if (StringUtils.isNotBlank(str)) {
return java.net.URLEncoder.encode(str, ENCODE);
}
return "";
}
}