| | |
| | | import java.math.BigInteger; |
| | | import java.net.InetAddress; |
| | | import java.net.NetworkInterface; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | |
| | | * @return Map对象 |
| | | * @version 2016年3月20日 11:03:01 |
| | | */ |
| | | public static Map convertBean2Map(Object bean) throws Exception { |
| | | public static Map convertBean2Map(Object bean,Set<String> existFild) throws Exception { |
| | | Class type = bean.getClass(); |
| | | Map returnMap = new HashMap(); |
| | | BeanInfo beanInfo = Introspector.getBeanInfo(type); |
| | | PropertyDescriptor[] propertyDescriptors = beanInfo |
| | | .getPropertyDescriptors(); |
| | | Field[] declaredFields = type.getDeclaredFields(); |
| | | Map<String, String> fieldMap = new HashMap(); |
| | | String existField = ""; |
| | | for (Field declaredField : declaredFields) { |
| | | declaredField.setAccessible(true); |
| | |
| | | Boolean fieldValue = tableField.exist(); |
| | | if(fieldValue == false){ |
| | | existField += declaredField.getName().toLowerCase()+","; |
| | | } |
| | | String value = tableField.value(); |
| | | if(net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils.isNotBlank(value)){ |
| | | fieldMap.put(declaredField.getName(), value); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if (result != null) { |
| | | if ("data".equals(propertyName)){ |
| | | returnMap.putAll((Map) result); |
| | | }else { |
| | | returnMap.put(propertyName, result); |
| | | if(existFild == null){ |
| | | returnMap.putAll((Map) result); |
| | | }else{ |
| | | Map resulMap = (Map) result; |
| | | for (Object o : resulMap.keySet()) { |
| | | if(existFild.contains(o)){ |
| | | returnMap.put(o,resulMap.get(o)); |
| | | } |
| | | } |
| | | } |
| | | }else if(existFild.contains((fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName).toLowerCase())){ |
| | | returnMap.put(fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName, result); |
| | | } |
| | | } else { |
| | | returnMap.put(propertyName, ""); |
| | | } else if(existFild.contains((fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName).toLowerCase())){ |
| | | returnMap.put(fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName, ""); |
| | | } |
| | | } |
| | | } |
| | |
| | | // String sqlField = camelToUnderscore(key); |
| | | |
| | | |
| | | if (map.containsKey(key.toUpperCase())) { |
| | | if (map.containsKey(key.toUpperCase(Locale.ROOT))||map.containsKey(key.toLowerCase(Locale.ROOT))) { |
| | | try { |
| | | Object value = map.get(key.toUpperCase()); |
| | | Object value=""; |
| | | if (map.containsKey(key.toUpperCase(Locale.ROOT))) { |
| | | value = map.get(key.toUpperCase()); |
| | | }else if(map.containsKey(key.toLowerCase(Locale.ROOT))){ |
| | | value = map.get(key.toLowerCase()); |
| | | } |
| | | // 得到property对应的setter方法 |
| | | Method setter = property.getWriteMethod(); |
| | | Class<?> type = property.getPropertyType(); |
| | |
| | | return beanList; |
| | | } |
| | | |
| | | |
| | | public static String camelToUnderscore(String name) { |
| | | if (name == null && name.length() <= 0) { |
| | | return name; |