@Test public void getMapToBeanTest() { Map<String, Object> map = new HashMap<String, Object>() { private static final long serialVersionUID = 1L; { put("id", "id0"); put("name", "name0"); } }; UseEntity entity = UseEntity.mapToBean(map, UseEntity.class); assertNotNull(entity); assertEquals("id0", entity.getId()); assertEquals("name0", entity.getName()); }
public static <T extends BaseEntity> T mapToBean(Map<String, Object> beanMap, Class<T> beanType) { if (beanType == null) { throw new EntityException("beanType不能为空"); } if (beanMap == null) { return null; } try { final T bean = beanType.newInstance(); beanMap.forEach((key, value) -> bean.setAttributeValue(key, value)); return bean; } catch (final InstantiationException | IllegalAccessException e) { throw new EntityException(e.getMessage(), e); } }
BaseEntity implements Cloneable, Serializable { public static <T extends BaseEntity> T mapToBean(Map<String, Object> beanMap, Class<T> beanType) { if (beanType == null) { throw new EntityException("beanType不能为空"); } if (beanMap == null) { return null; } try { final T bean = beanType.newInstance(); beanMap.forEach((key, value) -> bean.setAttributeValue(key, value)); return bean; } catch (final InstantiationException | IllegalAccessException e) { throw new EntityException(e.getMessage(), e); } } }
BaseEntity implements Cloneable, Serializable { public static <T extends BaseEntity> T mapToBean(Map<String, Object> beanMap, Class<T> beanType) { if (beanType == null) { throw new EntityException("beanType不能为空"); } if (beanMap == null) { return null; } try { final T bean = beanType.newInstance(); beanMap.forEach((key, value) -> bean.setAttributeValue(key, value)); return bean; } catch (final InstantiationException | IllegalAccessException e) { throw new EntityException(e.getMessage(), e); } }  }
BaseEntity implements Cloneable, Serializable { public static <T extends BaseEntity> T mapToBean(Map<String, Object> beanMap, Class<T> beanType) { if (beanType == null) { throw new EntityException("beanType不能为空"); } if (beanMap == null) { return null; } try { final T bean = beanType.newInstance(); beanMap.forEach((key, value) -> bean.setAttributeValue(key, value)); return bean; } catch (final InstantiationException | IllegalAccessException e) { throw new EntityException(e.getMessage(), e); } }  String[] attributeNames(); @SuppressWarnings("unchecked") T attributeValue(final String fieldName); T attributeValue(final String fieldName, final T defaultValue); void setAttributeValue(final String fieldName, final Object value); void setAttributeValue(final String fieldName, final Object value, final boolean isCase); Map<String, Object> beanToMap(); static T mapToBean(Map<String, Object> beanMap, Class<T> beanType); static List<T> mapToBeans(final List<Map<String, Object>> beanMaps, final Class<T> beanType); static Map<String, Method> paramMethods(Class<?> cls); static Map<String, Field> paramFields(Class<?> cls); Collection<Method> methods(); Collection<Field> fields(); @Override BaseEntity clone(); @Override String toString(); }
BaseEntity implements Cloneable, Serializable { public static <T extends BaseEntity> T mapToBean(Map<String, Object> beanMap, Class<T> beanType) { if (beanType == null) { throw new EntityException("beanType不能为空"); } if (beanMap == null) { return null; } try { final T bean = beanType.newInstance(); beanMap.forEach((key, value) -> bean.setAttributeValue(key, value)); return bean; } catch (final InstantiationException | IllegalAccessException e) { throw new EntityException(e.getMessage(), e); } }  String[] attributeNames(); @SuppressWarnings("unchecked") T attributeValue(final String fieldName); T attributeValue(final String fieldName, final T defaultValue); void setAttributeValue(final String fieldName, final Object value); void setAttributeValue(final String fieldName, final Object value, final boolean isCase); Map<String, Object> beanToMap(); static T mapToBean(Map<String, Object> beanMap, Class<T> beanType); static List<T> mapToBeans(final List<Map<String, Object>> beanMaps, final Class<T> beanType); static Map<String, Method> paramMethods(Class<?> cls); static Map<String, Field> paramFields(Class<?> cls); Collection<Method> methods(); Collection<Field> fields(); @Override BaseEntity clone(); @Override String toString();  }