admin 管理员组

文章数量: 1086019


2024年2月6日发(作者:word查找替换通配符一览表)

* get bean field value to value map * @param bean java bean * @return value map K:field V:value */ public static Map getBeanFieldValue(Object bean) { Class beanClass = ss(); Map valueMap = new HashMap(); Method[] methods = laredMethods(); Field[] fields = laredFields(); for (Field field : fields) { try { String fieldGetMethodName = spliceGetMethod(e()); if (!checkPropertyMethodExist(methods, fieldGetMethodName)) continue; Method fieldGetMethod = hod(fieldGetMethodName, new Class[] {}); Object fieldValue = (bean, new Object[] {}); if(null != fieldValue){ if ("Date".equals(e().getSimpleName())) { (e(), ((Date)fieldValue, "yyyy-MM-dd HH:mm:ss")); continue; } (e(), f(fieldValue)); } } catch (Exception e) { ("get bean value error" + field, e); } } return valueMap; } /** * set bean field value by value map * @param bean java bean * @param valueMap value map K:field V:value */ public static void setBeanFieldValue(Object bean, Map valueMap) { Class beanClass = ss(); Method[] methods = laredMethods(); Field[] fields = laredFields(); for (Field field : fields) { try { String fieldSetName = spliceSetMethod(e()); if (!checkPropertyMethodExist(methods, fieldSetName)) continue; Method fieldSetMet = hod(fieldSetName, e()); String value = (e()); (bean, getFieldTypeValue(field, value)); } catch (Exception e) { ("set bean value error" + field, e); } } } /** * return the corresponding type value according to the field property * @param field the field * @param value original value * @return corresponding type value */ public static Object getFieldTypeValue(Field field, Object value){ if(null == field || null == value || "".equals(value)) return null; String fieldType = e().getSimpleName(); if ("String".equals(fieldType)) return f(value); if ("Date".equals(fieldType)) { if (f(value).indexOf(':') > 0) return ((f(value), ern("yyyy-MM-dd

HH:mm:ss")).atZone(Default()).toInstant()); return ((f(value), ern("yyyy-MM-dd")).atStartOfDay(Default()).toInstant()); }

} if ("Integer".equals(fieldType) || "int".equals(fieldType)) return nt(f(value)); if ("Long".equalsIgnoreCase(fieldType)) return ong(f(value)); if ("Float".equalsIgnoreCase(fieldType)) return loat(f(value)); if ("Double".equalsIgnoreCase(fieldType)) return ouble(f(value)); if ("Short".equalsIgnoreCase(fieldType)) return hort(f(value)); if ("Byte".equalsIgnoreCase(fieldType)) return yte(f(value)); if ("BigDecimal".equalsIgnoreCase(fieldType)) return new BigDecimal(f(value)); if ("Character".equals(fieldType) || "char".equals(fieldType)) return f(value).charAt(0); if ("Boolean".equalsIgnoreCase(fieldType)) return oolean(f(value)); if ("TimeStamp".equalsIgnoreCase(fieldType)) return new Timestamp(f(f(value))); return value; } /** * judge whether it exists method of a property * @param methods object property method list * @param fieldMethod get or set method * @return true: exist, false: not exist */ public static boolean checkPropertyMethodExist(Method[] methods, String fieldMethod) { if(null == fieldMethod || "".equals(fieldMethod)) return false; for (Method met : methods) { if ((e())) return true; } return false; } /** * splicing property get or set methods * @param fieldName property name * @param method get or set method * @return methods after splicing */ public static String splicePropertyMethod(String fieldName, String method) { if (null == fieldName || "".equals(fieldName)) return null; return method + ing(0, 1).toUpperCase() + ing(1); } /** * splicing property get method * @param fieldName property * @return get method after splicing */ public static String spliceGetMethod(String fieldName) { return splicePropertyMethod(fieldName, "get"); } /** * splicing property set method * @param fieldName property * @return set method after splicing */ public static String spliceSetMethod(String fieldName) { return splicePropertyMethod(fieldName, "set"); }}3 : 测试Beanpackage util;import amp;import imal;import ;public class InvokeEntity {

private String name; private Character statue; private Integer age; private Float height; private Double weight; private Long amount; private Short number; private Byte work; private BigDecimal fund; private Date date; private Date time; private Timestamp dateTime; private boolean flag; public String getName() { return name; } public void setName(String name) { = name; } public Character getStatue() { return statue; } public void setStatue(Character statue) { = statue; } public Integer getAge() { return age; } public void setAge(Integer age) { = age; } public Float getHeight() { return height; } public void setHeight(Float height) { = height; } public Double getWeight() { return weight; } public void setWeight(Double weight) { = weight; } public Long getAmount() { return amount; } public void setAmount(Long amount) { = amount; } public Short getNumber() { return number; }

} public void setNumber(Short number) { = number; } public Byte getWork() { return work; } public void setWork(Byte work) { = work; } public BigDecimal getFund() { return fund; } public void setFund(BigDecimal fund) { = fund; } public Date getDate() { return date; } public void setDate(Date date) { = date; } public Date getTime() { return time; } public void setTime(Date time) { = time; } public Timestamp getDateTime() { return dateTime; } public void setDateTime(Timestamp dateTime) { me = dateTime; } public boolean isFlag() { return flag; } public void setFlag(boolean flag) { = flag; } @Override public String toString() { return "InvokeEntity{" + "name='" + name + ''' + ", statue=" + statue + ", age=" + age + ", height=" + height + ", weight=" + weight + ", amount=" + amount + ", number=" + number + ", work=" + work + ", fund=" + fund +

", fund=" + fund + ", date=" + date + ", time=" + time + ", dateTime=" + dateTime + ", flag=" + flag + '}'; }}4 : 参考链接


本文标签: 查找 替换 链接 参考 通配符