spring MVC Action里面怎么设置UTF-8编码集

复制代码
/*
编码转换,确保写数据库的时候不会出现乱码
*/
public class CodingConvert{ 

  public CodingConvert(){
   //
  }

public String toGb(String uniStr) {
        String gbStr = "";
        if (uniStr == null) {
            uniStr = "";
        }
        try {
            byte[] tempByte = uniStr.getBytes("ISO8859_1");
            gbStr = new String(tempByte, "UTF-8");
        }
        catch (Exception ex) {
        }
        return gbStr;
    }

    public String toUni(String gbStr) {
        String uniStr = "";
        if (gbStr == null) {
            gbStr = "";
        }
        try {
            byte[] tempByte = gbStr.getBytes("UTF-8");
            uniStr = new String(tempByte, "ISO8859_1");
        }
        catch (Exception ex) {
        }
        return uniStr;
    }
}
复制代码

 

posted @   wangwiz  阅读(384)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示