From 744f5bc38977f0152e7fde8f8da05cc69ec25209 Mon Sep 17 00:00:00 2001 From: qi Date: Thu, 2 Apr 2020 15:12:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lq/code/util/BeanUtil.java | 25 ++++++++----------- .../com/lq/code/util/CusAccessObjectUtil.java | 19 ++++++++++---- .../mybatisPlus/CreateMapperFileUtil.java | 1 - 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/lq/code/util/BeanUtil.java b/src/main/java/com/lq/code/util/BeanUtil.java index 3a40b67..7a9c070 100755 --- a/src/main/java/com/lq/code/util/BeanUtil.java +++ b/src/main/java/com/lq/code/util/BeanUtil.java @@ -16,10 +16,11 @@ import java.util.*; /** * Created by qi_liang on 2018/1/29. + * @author qi */ public class BeanUtil { - private static Logger LOGGER = LoggerFactory.getLogger(BeanUtil.class); + public final static Logger LOGGER = LoggerFactory.getLogger(BeanUtil.class); public static final String FILE_SYMBOL = "/"; @@ -71,7 +72,7 @@ public class BeanUtil { Class sourceClass = source.getClass(); List fieldList = getAllField(sourceClass); - Map fieldMap = new HashMap<>(); + Map fieldMap = new HashMap<>(fieldList.size()); for (Field field: fieldList){ field.setAccessible(true); fieldMap.put(field.getName(),field); @@ -85,18 +86,14 @@ public class BeanUtil { if (targerField!=null&&targerField.getGenericType().toString().equals(field.getGenericType().toString())){ try { PropertyDescriptor pd = new PropertyDescriptor(targerField.getName(), targerClass); - Method wM = pd.getWriteMethod();//获得写方法 + //获得写方法 + Method wM = pd.getWriteMethod(); Object value = targerField.get(source); if (value!=null) { wM.invoke(targer, value); } - // targerField.set(targer,value); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (IntrospectionException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); + } catch (Exception e) { + LOGGER.error(e.getMessage()); } } } @@ -111,7 +108,7 @@ public class BeanUtil { * @return */ public static Map getFiledType(Field[] fields){ - Map map=new HashMap<>(); + Map map=new HashMap<>(fields.length); for (Field field:fields){ map.put(field.getName(),field.getGenericType().toString()); } @@ -121,7 +118,7 @@ public class BeanUtil { public static List> getFileInfo(Field[] fields){ List> list=new ArrayList<>(); for (Field field:fields){ - Map map = new HashMap(); + Map map = new HashMap(2); map.put("fieldName",field.getName()); map.put("fieldType",field.getGenericType().toString()); list.add(map); @@ -135,7 +132,7 @@ public class BeanUtil { * @return */ public static List getFiledName(Field[] fields){ - List filedNameList=new ArrayList<>(); + List filedNameList=new ArrayList<>(fields.length); for (Field field:fields){ filedNameList.add(field.getName()); } @@ -148,7 +145,7 @@ public class BeanUtil { * @return */ public static List getFileTypeList(Field[] fields){ - List fileTypeList=new ArrayList<>(); + List fileTypeList=new ArrayList<>(fields.length); for (Field field:fields){ fileTypeList.add(field.getGenericType().toString()); } diff --git a/src/main/java/com/lq/code/util/CusAccessObjectUtil.java b/src/main/java/com/lq/code/util/CusAccessObjectUtil.java index 3ed843a..8c5abbb 100644 --- a/src/main/java/com/lq/code/util/CusAccessObjectUtil.java +++ b/src/main/java/com/lq/code/util/CusAccessObjectUtil.java @@ -2,8 +2,17 @@ package com.lq.code.util; import javax.servlet.http.HttpServletRequest; +/** + * 获取IP工具 + * @author qi + */ public class CusAccessObjectUtil { + /** + * 未知IP + */ + public static final String IP_UNKNOWN = "unknown"; + /** * 获取用户真实IP地址,不使用request.getRemoteAddr();的原因是有可能用户使用了代理软件方式避免真实IP地址, * @@ -20,19 +29,19 @@ public class CusAccessObjectUtil { */ public static String getIpAddress(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || IP_UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || IP_UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || IP_UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_CLIENT_IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || IP_UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_FORWARDED_FOR"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || IP_UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; diff --git a/src/main/java/com/lq/code/util/mybatisPlus/CreateMapperFileUtil.java b/src/main/java/com/lq/code/util/mybatisPlus/CreateMapperFileUtil.java index f34bea0..2e01dc4 100755 --- a/src/main/java/com/lq/code/util/mybatisPlus/CreateMapperFileUtil.java +++ b/src/main/java/com/lq/code/util/mybatisPlus/CreateMapperFileUtil.java @@ -40,7 +40,6 @@ public class CreateMapperFileUtil { } attributeBuffer.deleteCharAt(attributeBuffer.length()-1); columnBuffer.deleteCharAt(columnBuffer.length()-1); - //columnAndAttributeBuffer.deleteCharAt(columnAndAttributeBuffer.length()-1); result=result.replace("@tableColumn",columnBuffer); result=result.replace("@beanAttribute",attributeBuffer); result=result.replace("@ColumnEqAttribute",columnAndAttributeBuffer);