url上的中文字符是ISO-8859-1。后台获取中文乱码解决问题。

时间:2020-06-02 20:58:15   收藏:0   阅读:94

url上的中文字符是ISO-8859-1。后台获取中文乱码解决问题。

需要转码

public static String changeCharset(String str, String defaultValue)
    {
        if (str != null)
        {
            
            try
            {
                if ((StringUtils.isNotBlank(str)) && str.equals(
                        new String(str.getBytes("ISO-8859-1"), "ISO-8859-1")))
                {
                    return new String(str.getBytes("ISO-8859-1"), "UTF-8");
                }
                return str;
            }
            catch (UnsupportedEncodingException e)
            {
                throw new RuntimeException("字符串转换异常!!!!");
                
            }
        }
        return defaultValue;
    }

 

原文:https://www.cnblogs.com/ykpkris/p/13032662.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!