cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
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
41
42
43
44
45
46
47
48
49
50
51
52
53
package cn.ksource.core.util;
 
import java.net.URLDecoder;
import java.net.URLEncoder;
 
import org.apache.commons.lang.StringUtils;
 
public class AjaxUtil {
 
    /**
     * AJAX传递汉字,解决乱码
     * @param str
     * @return
     * @version V1.0.0
     * @author 杨凯
     * @date Jan 15, 2014 12:13:55 PM
     */
    public static String decode(String str){
        if (StringUtils.isBlank(str)) {
            return null;
        }
        String value = "";
        try {
            value = URLDecoder.decode(str, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }
    
    /**
     * 汉字加码
     * @param str
     * @return
     * @version V1.0.0
     * @author 杨凯
     * @date Mar 1, 2014 6:08:55 PM
     */
    public static String encode(String str){
        if (StringUtils.isBlank(str)) {
            return null;
        }
        String value = "";
        try {
            value = URLEncoder.encode(str, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }
    
    
}