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);