Commit 0427beb1dff0f26858b573d427ad07e41ba6385a
1 parent
e61acaa90e
Exists in
master
and in
1 other branch
修改了一个工具类
Showing 1 changed file with 24 additions and 1 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/BeanUtils.java
View file @
0427beb
| ... | ... | @@ -84,7 +84,7 @@ |
| 84 | 84 | * @createTime 2016年04月07日 14时47分 |
| 85 | 85 | * @discription object转map,建议处理异常 |
| 86 | 86 | */ |
| 87 | - public static Map<String, String> objectToMap(Object obj) { | |
| 87 | + public static Map<String, String> objectToStringMap(Object obj) { | |
| 88 | 88 | try { |
| 89 | 89 | Class c = obj.getClass(); |
| 90 | 90 | Map<String, String> map = new HashMap<String, String>(); |
| ... | ... | @@ -96,6 +96,29 @@ |
| 96 | 96 | Object result = pd.getReadMethod().invoke(obj); |
| 97 | 97 | if (result != null) { |
| 98 | 98 | map.put(key, result.toString()); |
| 99 | + } else { | |
| 100 | + map.put(key, ""); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + } | |
| 104 | + return map; | |
| 105 | + } catch (Exception e) { | |
| 106 | + throw new RuntimeException("object转map异常" + e); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + public static Map<String, Object> objectToObjectMap(Object obj) { | |
| 111 | + try { | |
| 112 | + Class c = obj.getClass(); | |
| 113 | + Map<String, Object> map = new HashMap<String, Object>(); | |
| 114 | + BeanInfo bi = Introspector.getBeanInfo(c); | |
| 115 | + PropertyDescriptor[] pds = bi.getPropertyDescriptors(); | |
| 116 | + for (PropertyDescriptor pd : pds) { | |
| 117 | + String key = pd.getName(); | |
| 118 | + if (!key.equals("class")) { | |
| 119 | + Object result = pd.getReadMethod().invoke(obj); | |
| 120 | + if (result != null) { | |
| 121 | + map.put(key, result); | |
| 99 | 122 | } else { |
| 100 | 123 | map.put(key, ""); |
| 101 | 124 | } |