From 05c6b5b0e9acc9f3f13d7c60d7ac190be1743541 Mon Sep 17 00:00:00 2001 From: gaojuan Date: Wed, 30 Mar 2022 16:39:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=80=E5=94=AE=E7=BA=BF=E7=B4=A2=E4=B9=B1?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fangjia/core/util/DataUtil.java | 10 ++++++ .../controllers/SaleLeadsController.java | 32 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java b/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java index 93218b265..c51c573f7 100644 --- a/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java +++ b/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java @@ -1805,6 +1805,16 @@ public class DataUtil { } } + public static boolean isChineseChar(String c) { + if (StringUtils.isNotBlank(c)) { + String temp = String.valueOf(c); + Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]+"); + Matcher matcher = pattern.matcher(temp); + return matcher.matches(); + } + return false; + } + public static void main(String[] args) { System.out.println(getFirstChar("ÎÄÔ£»¨Ô°")); System.out.println(getFirstChar("ÎÄâù»¨Ô°")); diff --git a/projects/fangjia-coresite/src/main/java/com/fangjia/coresite/controllers/SaleLeadsController.java b/projects/fangjia-coresite/src/main/java/com/fangjia/coresite/controllers/SaleLeadsController.java index 3f6881dd5..f8c75d856 100644 --- a/projects/fangjia-coresite/src/main/java/com/fangjia/coresite/controllers/SaleLeadsController.java +++ b/projects/fangjia-coresite/src/main/java/com/fangjia/coresite/controllers/SaleLeadsController.java @@ -1,5 +1,9 @@ package com.fangjia.coresite.controllers; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URLEncoder; import java.util.Date; import java.util.List; @@ -7,6 +11,7 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.fangjia.core.util.DataUtil; import org.apache.commons.lang.StringUtils; import com.fangjia.coresite.model.JsonModel; @@ -37,7 +42,7 @@ public class SaleLeadsController { } public Object doAddAction(SaleLeadsModel model, HttpServletRequest req, - HttpServletResponse res) { + HttpServletResponse res) throws UnsupportedEncodingException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { model.setViewType("redirect"); String refUrl = model.getBackUrl(); @@ -122,6 +127,8 @@ public class SaleLeadsController { } } + + saleLeads = converValue(saleLeads); saleLeadsService.save(saleLeads); if(StringUtils.isNotBlank(saleLeads.getBusiness()) && saleLeads.getBusiness().contains("_")){ @@ -162,6 +169,29 @@ public class SaleLeadsController { model.setViewParam("location", url); return model; } + + private SaleLeads converValue(SaleLeads saleLeads) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, UnsupportedEncodingException { +// + Field[] fields = saleLeads.getClass().getDeclaredFields(); + for(Field s : fields){ + String name = s.getName(); + String type = s.getGenericType().toString(); + if(type.contains("java.lang.String")){ + String fildName = name.substring(0,1).toUpperCase()+name.substring(1); + Method m = saleLeads.getClass().getMethod("get"+fildName); + String value = (String)m.invoke(saleLeads); + if(StringUtils.isNotBlank(value)){ + if(!DataUtil.isChineseChar(value)){ + String newValue = new String(value.getBytes("ISO8859-1"), "UTF-8"); + m = saleLeads.getClass().getMethod("set"+fildName,String.class); + m.invoke(saleLeads, newValue); + } + } + } + } + return saleLeads; + + } public Object addDownInfoAction(SaleLeadsModel model, HttpServletRequest req,