From 9167cdbcf303ad5cd320cd6da3913e26da885425 Mon Sep 17 00:00:00 2001 From: "zhangdaiscott@163.com" Date: Thu, 7 Jun 2018 16:18:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E9=AB=98=E8=80=83=E5=AD=A6=E5=AD=90?= =?UTF-8?q?=E5=8A=A0=E6=B2=B9=EF=BC=8CJEECG=203.7.6=20=E9=AB=98=E8=80=83?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E5=8A=A0=E5=BC=BA=E7=89=88=E6=9C=AC=E5=8F=91?= =?UTF-8?q?=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tag/core/easyui/TagUtil.java | 110 +++++++----------- 1 file changed, 42 insertions(+), 68 deletions(-) diff --git a/jeecg-framework/src/main/java/org/jeecgframework/tag/core/easyui/TagUtil.java b/jeecg-framework/src/main/java/org/jeecgframework/tag/core/easyui/TagUtil.java index c49bcf6b..dcd19cbf 100644 --- a/jeecg-framework/src/main/java/org/jeecgframework/tag/core/easyui/TagUtil.java +++ b/jeecg-framework/src/main/java/org/jeecgframework/tag/core/easyui/TagUtil.java @@ -8,7 +8,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; @@ -18,11 +17,9 @@ import org.codehaus.jackson.map.ObjectMapper; import org.jeecgframework.core.common.hibernate.qbc.PageList; import org.jeecgframework.core.common.model.json.ComboBox; import org.jeecgframework.core.common.model.json.DataGrid; -import org.jeecgframework.core.util.ContextHolderUtils; import org.jeecgframework.core.util.ReflectHelper; import org.jeecgframework.core.util.StringUtil; import org.jeecgframework.core.util.oConvertUtils; -import org.jeecgframework.tag.core.util.GzipUtilities; import org.jeecgframework.tag.vo.datatable.DataTableReturn; import org.jeecgframework.tag.vo.easyui.Autocomplete; import org.jeecgframework.web.system.pojo.base.TSRole; @@ -83,7 +80,7 @@ public class TagUtil { } value = reflectHelper.getMethodValue(fieldName)==null?"":reflectHelper.getMethodValue(fieldName); if (value !=""&&value != null && (FiledName.indexOf("_") != -1||FiledName.indexOf(".") != -1)) { - +// update-start--Author:zhangguoming Date:20140827 for:功能增强,添加处理对象中List属性字段的解析 if(value instanceof List) { Object tempValue = ""; for (Object listValue : (List)value) { @@ -93,10 +90,10 @@ public class TagUtil { } else { value = fieldNametoValues(childFieldName, value); } - +// update-end--Author:zhangguoming Date:20140827 for:功能增强,添加处理对象中List属性字段的解析 } if(value != "" && value != null) { - +// update-begin--Author:jb_longjb 龙金波 Date:20150313 for:处理json中可能包含的特殊字符,防止页面加载出错 value = converunicode(value.toString()); } return value; @@ -106,7 +103,7 @@ public class TagUtil { for (int i=0; i list, String[] footers, String dataStyle, int pageSize) throws Exception { //Object[] values = new Object[fields.length]; StringBuffer jsonTemp = new StringBuffer(); - + //update--begin--author:zhangjiaqiang date:20170413 for:支持jqgrid列表 json格式 if("jqgrid".equals(dataStyle)){ int totalPage = total % pageSize > 0 ? total / pageSize + 1 : total / pageSize; if(totalPage == 0) totalPage = 1; @@ -179,20 +176,23 @@ public class TagUtil { jsonTemp.append("{\"total\":" + total ); } jsonTemp.append(",\"rows\":["); - + //update--end--author:zhangjiaqiang date:20170413 for:支持jqgrid列表 json格式 int i; String fieldName; - + + //update--begin--author:scott date:20170918 for:list为null问题处理------- if(list==null){ list = new ArrayList(); } - + //update--end--author:scott date:20170918 for:list为null问题处理------- for (int j = 0; j < list.size(); ++j) { - + //update-begin--Author:zhoujf Date:20170323 for:TASK #1774 【bug】树列表,下一级没了,图标是文件夹的问题,应该是节点(优化) + //update-begin--Author:zhoujf Date:20170315 for:TASK #1774 【bug】树列表,下一级没了,图标是文件夹的问题,应该是节点 //jsonTemp.append("{"); jsonTemp.append("{\"state\":\"closed\","); - + //update-end--Author:zhoujf Date:20170315 for:TASK #1774 【bug】树列表,下一级没了,图标是文件夹的问题,应该是节点 + //update-end--Author:zhoujf Date:20170323 for:TASK #1774 【bug】树列表,下一级没了,图标是文件夹的问题,应该是节点(优化) Object fieldValue = null; for (i = 0; i < fields.length; ++i) { fieldName = fields[i].toString(); @@ -201,9 +201,9 @@ public class TagUtil { else { fieldValue = fieldNametoValues(fieldName, list.get(j)); } - + //update-begin--Author:zhoujf Date:20170315 for:对象为null时返回空串而不是“null” jsonTemp.append("\"" + fieldName + "\"" + ":\"" + getStringValue(fieldValue).replace("\"", "\\\"") + "\""); - + //update-end--Author:zhoujf Date:20170315 for:对象为null时返回空串而不是“null” if (i != fields.length - 1) { jsonTemp.append(","); } @@ -240,7 +240,7 @@ public class TagUtil { jsonTemp.append("}"); return jsonTemp.toString(); } - + //update--begin--author:gj_shaojc-- date:20180604--for:TASK #2763 【确认问题】合计金额展示问题,国际通用格式 如:61,100.00 确认是否存在问题 /** * 循环LIST对象拼接EASYUI格式的JSON数据Footers是json格式的数据 * @param fields @@ -307,12 +307,13 @@ public class TagUtil { jsonTemp.append("}"); return jsonTemp.toString(); } - + //update--end--author:gj_shaojc-- date:20180604--for:TASK #2763 【确认问题】合计金额展示问题,国际通用格式 如:61,100.00 确认是否存在问题 + //update-begin--Author:zhoujf Date:20170315 for:对象为null时返回空串而不是“null” //为空时返回空串 private static String getStringValue(Object obj){ return (obj == null) ? "" : obj.toString(); } - + //update-end--Author:zhoujf Date:20170315 for:对象为null时返回空串而不是“null” /** * 计算指定列的合计 @@ -414,19 +415,19 @@ public class TagUtil { private static JSONObject getJson(DataGrid dg) { JSONObject jObject = null; try { - + //update--begin--author:zhangjiaqiang date:20170413 for:支持jqgrid列表 json格式 if(!StringUtil.isEmpty(dg.getFooter())){ - + //update--begin--author:gj_shaojc-- date:20180604--for:TASK #2763 【确认问题】合计金额展示问题,国际通用格式 如:61,100.00 确认是否存在问题 if(dg.getFooter().startsWith("[")){ jObject = JSONObject.parseObject(listtojsonByFootersJson(dg.getField().split(","), dg.getTotal(), dg.getResults(),dg.getFooter(),dg.getDataStyle(),dg.getRows())); }else{ jObject = JSONObject.parseObject(listtojson(dg.getField().split(","), dg.getTotal(), dg.getResults(),dg.getFooter().split(","),dg.getDataStyle(),dg.getRows())); } - + //update--end--author:gj_shaojc-- date:20180604--for:TASK #2763 【确认问题】合计金额展示问题,国际通用格式 如:61,100.00 确认是否存在问题 }else{ jObject = JSONObject.parseObject(listtojson(dg.getField().split(","), dg.getTotal(), dg.getResults(),null,dg.getDataStyle(),dg.getRows())); } - + //update--end--author:zhangjiaqiang date:20170413 for:支持jqgrid列表 json格式 } catch (Exception e) { e.printStackTrace(); } @@ -560,31 +561,21 @@ public class TagUtil { PrintWriter pw = null; try { - - HttpServletRequest request = ContextHolderUtils.getRequest(); - if (GzipUtilities.isGzipSupported(request) && !GzipUtilities.isGzipDisabled(request)) { - log.debug("-------datagrid----json-----开启Gzip压缩-------------"); - pw = GzipUtilities.getGzipWriter(response); - response.setHeader("Content-Encoding", "gzip"); - } else { - pw = response.getWriter(); - } - - + pw=response.getWriter(); pw.write(object.toString()); pw.flush(); - pw.close(); } catch (IOException e) { e.printStackTrace(); }finally{ try { - + //update-begin--Author:scott Date:20160530 for:清空降低缓存占用 + pw.close(); object.clear(); object = null; dg.clear(); dg = null; System.gc(); - + //update-end--Author:scott Date:20160530 for:清空降低缓存占用 } catch (Exception e) { e.printStackTrace(); } @@ -604,30 +595,22 @@ public class TagUtil { JSONArray rows = object.getJSONArray("rows"); PrintWriter pw = null; try { - - HttpServletRequest request = ContextHolderUtils.getRequest(); - if (GzipUtilities.isGzipSupported(request) && !GzipUtilities.isGzipDisabled(request)) { - log.info("-------datagrid----json-----开启Gzip压缩-------------"); - pw = GzipUtilities.getGzipWriter(response); - response.setHeader("Content-Encoding", "gzip"); - } else { - pw = response.getWriter(); - } - + pw = response.getWriter(); pw.write(rows.toString()); pw.flush(); - pw.close(); } catch (IOException e) { e.printStackTrace(); }finally{ try { - + //update-begin--Author:scott Date:20160530 for:清空降低缓存占用 + pw.close(); object.clear(); - + //update-end--Author:scott Date:20160530 for:清空降低缓存占用 + //update-begin--Author:scott Date:20170830 for:TASK #1756 【性能优化】分页查询存在写法问题,性能 CriteriaQuery cq 清空--- dg.clear(); dg = null; System.gc(); - + //update-end--Author:scott Date:20170830 for:TASK #1756 【性能优化】分页查询存在写法问题,性能 CriteriaQuery cq 清空--- } catch (Exception e) { e.printStackTrace(); } @@ -652,31 +635,21 @@ public class TagUtil { } PrintWriter pw = null; try { - - HttpServletRequest request = ContextHolderUtils.getRequest(); - if (GzipUtilities.isGzipSupported(request) && !GzipUtilities.isGzipDisabled(request)) { - log.debug("-------datagrid----json-----开启Gzip压缩-------------"); - pw = GzipUtilities.getGzipWriter(response); - response.setHeader("Content-Encoding", "gzip"); - } else { - pw = response.getWriter(); - } - + pw = response.getWriter(); pw.write(object.toString()); pw.flush(); - pw.close(); } catch (IOException e) { e.printStackTrace(); }finally{ try { - + //update-begin--Author:scott Date:20160530 for:清空降低缓存占用 + pw.close(); object.clear(); - dg.clear(); dg = null; System.gc(); extMap = null; - + //update-begin--Author:scott Date:20160530 for:清空降低缓存占用 } catch (Exception e2) { // TODO: handle exception } @@ -814,7 +787,8 @@ public class TagUtil { param += "'\"+index+\"'";// 传出行索引号参数 return param; } - + + //update-begin--Author:luobaoli Date:20150711 for:新增方法,将存储过程返回的数据解析为json格式 public static String getJson(List fields,List datas){ if(datas!=null && datas.size()>0){ StringBuffer sb = new StringBuffer(); @@ -834,7 +808,7 @@ public class TagUtil { return "{\"total\":\"0\",\"rows\":[]}"; } } - + //update-begin--Author:luobaoli Date:20150711 for:新增方法,将存储过程返回的数据解析为json格式 public static String getJsonByMap(List fields,List> datas){ if(datas!=null && datas.size()>0){