浏览代码

Merge branch 'dev' of wujunjie/patient-co-management into dev

yeshijie 7 年之前
父节点
当前提交
606ffe19f7

+ 3 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/EncodingFilter.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.interceptors;
import com.yihu.wlyy.util.CodeFomat;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -37,6 +38,8 @@ public class EncodingFilter implements Filter {
            for (int i = 0; i < values.length; i++) {
                String value = values[i];
                newRequest.removeAttribute(key);
//                解决%、+后中文以英文编码传入URLDecoder异常
                value = CodeFomat.dateToChinese(value);
                newRequest.addParameter(key, URLDecoder.decode((value),"utf-8"));
            }
        }

+ 3 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorGuidanceTempService.java

@ -3,6 +3,7 @@ package com.yihu.wlyy.service.template;
import com.yihu.wlyy.entity.template.DoctorGuidanceTemp;
import com.yihu.wlyy.repository.template.DoctorGuidanceTempDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.CodeFomat;
import com.yihu.wlyy.util.CommonUtil;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -59,6 +60,7 @@ public class DoctorGuidanceTempService extends BaseService {
        Map temp = (Map) jdbcTemplate.queryForMap(sql, modelCode);
        String modelName = (String) temp.get("model_name");
        String content = (String) temp.get("content");
        content = CodeFomat.chineseToDate(content);
        String imagesUrl = (String) temp.get("images_url");
//        多图按逗号分割保存成数组
        String[] imagesArray = null;
@ -86,6 +88,7 @@ public class DoctorGuidanceTempService extends BaseService {
     * @return
     */
    public DoctorGuidanceTemp add(String doctor, String content, String modelName, String imagesUrl) {
        content = CodeFomat.dateToChinese(content);
        DoctorGuidanceTemp guidanceTemp = new DoctorGuidanceTemp();
        String imageUrls = "";
        String imageRow = "";

+ 46 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/CodeFomat.java

@ -0,0 +1,46 @@
package com.yihu.wlyy.util;
import java.net.URLDecoder;
/**
 * Created by Reece on 2017/8/28/028.
 * <p>
 * 特殊字符编码转换
 */
public class CodeFomat {
    /**
     *  解决%、+后中文以英文编码传入URLDecoder异常
     * @param resource 英文编码
     * @return 中文编码
     */
    public static String dateToChinese(String resource) {
        String data = resource.toString();
        try {
            data = data.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
            data = data.replaceAll("\\+", "%2B");
//            data = URLDecoder.decode(data, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }
    /**
     *  解决数据库以%25代替%、+后的数据展示问题
     * @param resource 中文编码
     * @return 英文编码
     */
    public static String chineseToDate(String resource) {
        String data = resource.toString();
        try {
            data = data.replaceAll("%25", "%");
            data = data.replaceAll("%2B", "+");
//            data = URLDecoder.decode(data, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }
}