Java Code Examples for org.springframework.cglib.beans.BeanMap#create()
The following examples show how to use
org.springframework.cglib.beans.BeanMap#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanMapUtils.java From Lottor with MIT License | 7 votes |
/** * 将List<Map<String,Object>>转换为List<T> * * @param maps * @param clazz * @return * @throws InstantiationException * @throws IllegalAccessException */ public static <T> List<T> listToBean(List<Object> maps, Class<T> clazz) throws InstantiationException, IllegalAccessException { List<T> list = Lists.newArrayList(); if (maps != null && maps.size() > 0) { Object map; T bean; for (int i = 0, size = maps.size(); i < size; i++) { map = maps.get(i); bean = clazz.newInstance(); BeanMap beanMap = BeanMap.create(bean); list.add(bean); } } return list; }
Example 2
Source File: AbstractContextProvider.java From bdf3 with Apache License 2.0 | 5 votes |
protected Object getRealContext(Object obj, String dataPath) { if (StringUtils.isEmpty(dataPath)) { return obj; } String[] path = dataPath.split("\\."); Object target = obj; BeanMap beanMap = BeanMap.create(target); for (String property : path) { target = beanMap.get(property); } return target; }
Example 3
Source File: SoapClient.java From jea with Apache License 2.0 | 5 votes |
private Object copytoSoapObject(Object param, Class<?> soapClass) throws Exception { Object soapObject = soapClass.newInstance(); if (soapObject instanceof java.lang.String) { soapObject = param.toString(); } else { BeanMap beanMap = BeanMap.create(soapObject); DynamicDTO dto = (DynamicDTO) param; for (String key : dto.properties()) { beanMap.put(key, dto.getValue(key)); } } return soapObject; }
Example 4
Source File: DynamicDTO.java From jea with Apache License 2.0 | 5 votes |
/** * 建议用于SOAP对象的转换,一般的JavaBean请继承BaseDTO或BasePO * @param obj */ public DynamicDTO(Object obj){ generator = new BeanGenerator(); valueMap = new TreeMap<String, Object>(); beanObject = obj; beanMap = BeanMap.create(obj); valueMap.putAll(beanMap); }
Example 5
Source File: DynamicEntityGeneratorTest.java From we-cmdb with Apache License 2.0 | 5 votes |
@Test @Ignore public void operateAdmMenuThenSuccessfully() throws Exception { List<FieldNode> fields = Arrays.asList(new FieldNode(DynamicEntityType.CI, 1, "idAdmMenu", Integer.class, "id_adm_menu", true), new FieldNode(DynamicEntityType.CI, 1, "classPath", String.class, "class_path"), new FieldNode(DynamicEntityType.CI, 1, "isActive", Integer.class, "is_active"), new FieldNode(DynamicEntityType.CI, 1, "name", String.class, "name"), new FieldNode(DynamicEntityType.CI, 1, "otherName", String.class, "other_name"), new FieldNode(DynamicEntityType.CI, 1, "parentIdAdmMenu", Integer.class, "parent_id_adm_menu"), new FieldNode(DynamicEntityType.CI, 1, "remark", String.class, "remark"), new FieldNode(DynamicEntityType.CI, 1, "seqNo", Integer.class, "seq_no"), new FieldNode(DynamicEntityType.CI, 1, "url", String.class, "url")); byte[] domainBuf = DynamicEntityGenerator.generate("test.domain.AdmMenu", "adm_menu", fields); Class clzz = entityCL.getClass(domainBuf); HibernateJpaEntityManagerFactory ciManagerFactory = new HibernateJpaEntityManagerFactory(Arrays.asList(clzz), dataSource, entityCL, datasourceProperties.getSchema()); EntityManager ciEntityManager = ciManagerFactory.getEntityManagerFactory() .createEntityManager(); Object entity = clzz.newInstance(); BeanMap beanMap = BeanMap.create(entity); beanMap.put("name", "test menu"); beanMap.put("remark", "test remark"); beanMap.put("seqNo", 99); beanMap.put("idAdmMenu", 100); EntityTransaction transaction = ciEntityManager.getTransaction(); transaction.begin(); Object updatedEntity = ciEntityManager.merge(entity); System.out.println("id:" + BeanMap.create(updatedEntity) .get("idAdmMenu")); transaction.commit(); }
Example 6
Source File: ObjectUtil.java From SENS with GNU General Public License v3.0 | 5 votes |
public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key+"", beanMap.get(key)); } } return map; }
Example 7
Source File: WarningHelper.java From seppb with MIT License | 5 votes |
default Map<String, Object> beanToMap(@NonNull T t) { Map<String, Object> defectMap = Maps.newHashMap(); BeanMap beanMap = BeanMap.create(t); for (Object key : beanMap.keySet()) { Object value = valueToDouble(null == beanMap.get(key) ? 0.0001 : beanMap.get(key)); defectMap.put(String.valueOf(key), value); } return defectMap; }
Example 8
Source File: AuditUtil.java From pmq with Apache License 2.0 | 5 votes |
public static Map<String, String> convertMap(Object source) { if (source== null) { return new HashMap<>(); } BeanMap sourceBeanMap = BeanMap.create(source); Map<String, String> sourceFieldMap = new HashMap<>(); for (Object key: sourceBeanMap.keySet()) { sourceFieldMap.put(key.toString(), JsonUtil.toJson(sourceBeanMap.get(key))); } return sourceFieldMap; }
Example 9
Source File: BeanUtil.java From web-flash with MIT License | 5 votes |
/** * 将对象装换为map * @param bean * @return */ public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key+"", beanMap.get(key)); } } return map; }
Example 10
Source File: Utils.java From faster-framework-project with Apache License 2.0 | 5 votes |
/** * bean转map * * @param bean 原始bean * @param <T> 泛型 * @return map */ public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = new HashMap<>(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key + "", beanMap.get(key)); } } return map; }
Example 11
Source File: DynamicDTO.java From jea with Apache License 2.0 | 5 votes |
/** * 转换器,设置DynamicDTO的属性值到对应的Model对象 * * @param target */ @SuppressWarnings("unchecked") public void convert(BaseModel target) { BeanMap tmp = BeanMap.create(target); Iterator<String> keys = tmp.keySet().iterator(); String key = null; while(keys.hasNext()){ key = keys.next(); if(beanMap.containsKey(key)){ StringConverter converter = new StringConverter(); TypeConverterManager.register(String.class, converter); tmp.put(key, TypeConverterManager.convertType(beanMap.get(key), tmp.getPropertyType(key))); } } }
Example 12
Source File: DynamicDTO.java From jea with Apache License 2.0 | 5 votes |
public Object getCloneBean() { try { Object tmpObject = generator.create(); BeanMap tmpMap = BeanMap.create(tmpObject); tmpMap.putAll(valueMap); return tmpObject; } catch (Exception e) { return null; } }
Example 13
Source File: DynamicEntityHolder.java From we-cmdb with Apache License 2.0 | 4 votes |
public DynamicEntityHolder(DynamicEntityMeta entityMeta, Object entityObj) { this.entityMeta = entityMeta; this.entityObj = entityObj; entityBeanMap = BeanMap.create(entityObj); }
Example 14
Source File: BeanMapUtils.java From Lottor with MIT License | 4 votes |
public static <T> T objectMapToBean(Map<Object,Object> map, T bean) { BeanMap beanMap = BeanMap.create(bean); beanMap.putAll(map); return bean; }
Example 15
Source File: DynamicDTO.java From jea with Apache License 2.0 | 4 votes |
private void generateBean() throws Exception { beanObject = generator.create(); beanMap = BeanMap.create(beanObject); beanMap.putAll(valueMap); }
Example 16
Source File: BeanUtil.java From blade-tool with GNU Lesser General Public License v3.0 | 2 votes |
/** * 将对象装成map形式 * @param bean 源对象 * @return {Map} */ @SuppressWarnings("unchecked") public static Map<String, Object> toMap(Object bean) { return BeanMap.create(bean); }
Example 17
Source File: BeanUtil.java From flash-waimai with MIT License | 2 votes |
/** * 将map装换为javabean对象 * @param map * @param bean * @return */ public static <T> T mapToBean(Map<String, Object> map,T bean) { BeanMap beanMap = BeanMap.create(bean); beanMap.putAll(map); return bean; }
Example 18
Source File: BeanMapUtils.java From Lottor with MIT License | 2 votes |
/** * 将map装换为javabean对象 * * @param map key value 为string 的map * @param bean * @return */ public static <T> T stringMapToBean(Map<String,String> map, T bean) { BeanMap beanMap = BeanMap.create(bean); beanMap.putAll(map); return bean; }
Example 19
Source File: BeanUtil.java From web-flash with MIT License | 2 votes |
/** * 将map装换为javabean对象 * @param map * @param bean * @return */ public static <T> T mapToBean(Map<String, Object> map,T bean) { BeanMap beanMap = BeanMap.create(bean); beanMap.putAll(map); return bean; }
Example 20
Source File: Utils.java From faster-framework-project with Apache License 2.0 | 2 votes |
/** * 将map装换为javabean对象 * * @param map 原始map * @param bean 实例化空bean * @param <T> 泛型 * @return 填充后的bean */ public static <T> T mapToBean(Map<String, Object> map, T bean) { BeanMap beanMap = BeanMap.create(bean); beanMap.putAll(map); return bean; }