Parcourir la source

bean 转map bug 修复

吴学文 il y a 7 ans
Parent
commit
7b7d6e2a91

+ 1 - 2
CommunityService/src/main/java/com/java110/community/smo/impl/CommunityInnerServiceSMOImpl.java

@@ -33,8 +33,7 @@ public class CommunityInnerServiceSMOImpl extends BaseServiceSMO implements ICom
 
         logger.debug("communityMemberDto:{}", JSONObject.toJSONString(communityMemberDto));
 
-        Map info = new HashMap();
-        List<Map> communityMembers = communityServiceDaoImpl.getCommunityMembers(BeanConvertUtil.covertBean(communityMemberDto, info));
+        List<Map> communityMembers = communityServiceDaoImpl.getCommunityMembers(BeanConvertUtil.beanCovertMap(communityMemberDto));
         return BeanConvertUtil.covertBeanList(communityMembers, CommunityMemberDto.class);
     }
 

+ 3 - 3
java110-common/src/main/java/com/java110/common/util/BeanConvertUtil.java

@@ -89,11 +89,11 @@ public final class BeanConvertUtil {
      * @param orgBean 原始bean
      * @return map对象
      */
-    public static  Map<String, Object> beanCovertMap(Object orgBean) {
-        Map<String, Object> newMap = new HashMap<String, Object>();
+    public static  Map beanCovertMap(Object orgBean) {
+        Map newMap = null;
 
         try {
-            BeanUtils.populate(orgBean, newMap);
+            newMap = BeanUtils.describe(orgBean);
         } catch (Exception e) {
             throw new RuntimeException("bean转换Map失败", e);
         }

+ 28 - 0
java110-common/src/test/java/com/java110/common/util/BeanConvertUtilTest.java

@@ -0,0 +1,28 @@
+package com.java110.common.util;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.dto.CommunityMemberDto;
+import junit.framework.TestCase;
+import org.apache.commons.beanutils.BeanUtils;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+public class BeanConvertUtilTest extends TestCase {
+
+    public void testCovertBean() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
+
+        CommunityMemberDto communityMemberDto = new CommunityMemberDto();
+        communityMemberDto.setMemberTypeCd("123");
+        communityMemberDto.setStatusCd("1");
+        communityMemberDto.setMemberId("123123");
+
+        Map info = new HashMap();
+
+        //Map _info  = BeanConvertUtil.beanCovertMap(communityMemberDto);
+        Map _info  = BeanUtils.describe(communityMemberDto);
+
+        System.out.println(JSONObject.toJSONString(_info));
+    }
+}