shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.walker.infrastructure.utils;
 
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
 
public class UrlUtils {
 
    /**
     * 转码前端通过URL提交的参数。
     * @param url
     * @return
     * @date 2023-05-17
     */
    public static String decode(String url) {
        return decode(url, StringUtils.DEFAULT_CHARSET_UTF8);
    }
 
    public static String decode(String content, Charset charset) {
        if (null == charset) {
            charset = defaultCharset();
        }
        return decode(content, charset.name());
    }
 
    public static Charset defaultCharset() {
        return Charset.defaultCharset();
    }
 
    public static final String decode(String url, String charset){
        if(StringUtils.isEmpty(url)){
            return url;
        }
        try {
            return URLDecoder.decode(url, charset);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("decode错误,字符集不支持:" + charset, e);
        }
    }
}