修复部分代码

master
星期八 5 years ago
parent eb384365ff
commit 744f5bc389
  1. 25
      src/main/java/com/lq/code/util/BeanUtil.java
  2. 19
      src/main/java/com/lq/code/util/CusAccessObjectUtil.java
  3. 1
      src/main/java/com/lq/code/util/mybatisPlus/CreateMapperFileUtil.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<Field> fieldList = getAllField(sourceClass);
Map<String,Field> fieldMap = new HashMap<>();
Map<String,Field> 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<String,String> getFiledType(Field[] fields){
Map<String,String> map=new HashMap<>();
Map<String,String> 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<Map<String,String>> getFileInfo(Field[] fields){
List<Map<String,String>> list=new ArrayList<>();
for (Field field:fields){
Map<String,String> map = new HashMap();
Map<String,String> 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<String> getFiledName(Field[] fields){
List<String> filedNameList=new ArrayList<>();
List<String> filedNameList=new ArrayList<>(fields.length);
for (Field field:fields){
filedNameList.add(field.getName());
}
@ -148,7 +145,7 @@ public class BeanUtil {
* @return
*/
public static List<String> getFileTypeList(Field[] fields){
List<String> fileTypeList=new ArrayList<>();
List<String> fileTypeList=new ArrayList<>(fields.length);
for (Field field:fields){
fileTypeList.add(field.getGenericType().toString());
}

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

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

Loading…
Cancel
Save