map 转指定类型实体类 map

用于转换成符合实体类属性的 map

map 转指定类型实体类 map
public Map<String, Object> convertMapToBeanMap(Map<String, Object> params, Class clazz) throws IntrospectionException {    Map<String, Object> finalMap = new HashMap<>();
    BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
    PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
    for (int i = 0; i < propertyDescriptors.length; i++) {        PropertyDescriptor descriptor = propertyDescriptors[i];
        String propertyName = descriptor.getName();
        if (!propertyName.equals("class")) {            if (params.containsKey(propertyName)) {                finalMap.put(propertyName, params.get(propertyName));
            }
        }
    }
    return finalMap;
}


手机扫描二维码访问

    本文标题:《map 转指定类型实体类 map》作者:极四维博客
    原文链接:https://cway.top/post/563.html
    特别注明外均为原创,转载请注明。

    分享到微信

    扫描二维码

    可在微信查看或分享至朋友圈。

    相关文章

    ff ff 发布于 2019-11-10 16:35:55  
    #cmt34
    电商专用快递网站www.dh5u.com单号无忧 回复
    发表评论:

    ◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

    «    2025年5月    »
    1234
    567891011
    12131415161718
    19202122232425
    262728293031

    搜索

    控制面板

    您好,欢迎到访网站!
      查看权限

    最新留言

    文章归档

    • 订阅本站的 RSS 2.0 新闻聚合