用于转换成符合实体类属性的 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; }
#cmt34