标签:else script == row div timestamp 支持 dHash rip
import com.google.common.base.CaseFormat; import com.google.common.base.Converter; class Utils{ private static Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.UPPER_UNDERSCORE); //Object转换为Map(实体对象转换成带下划线的map) public static Map<String,Object> objToMap(Object obj) throws Exception{ Map<String,Object> map = new LinkedHashMap<String, Object>(); Field[] fields = obj.getClass().getDeclaredFields(); for(Field field : fields){ field.setAccessible(true); map.put(converter.convert(field.getName()) , field.get(obj)); } return map; } }
public class CamelUnderlineUtil { private static final char UNDERLINE =‘_‘; public static String camelToUnderline(String param) { if (StringUtil.isEmpty(param)) { return ""; } StringBuilder sb = new StringBuilder(); int len = param.length(); for (int i = 0; i < len; i++) { char c = param.charAt(i); if (Character.isUpperCase(c)) { sb.append(UNDERLINE); sb.append(Character.toLowerCase(c)); } else { sb.append(c); } } return sb.toString(); } public static String underlineToCamel(String param){ if (StringUtil.isEmpty(param)) { return ""; } StringBuilder sb = new StringBuilder(); int len = param.length(); for (int i = 0; i < len; i++) { char c = param.charAt(i); if (c==UNDERLINE) { if(++i<len){ sb.append(Character.toUpperCase(param.charAt(i))); } } else { sb.append(c); } } return sb.toString(); } }
private Map<String, String> convertObjectToMap(Object obj, Class clazz) throws Exception { Map<String, String> dstMap = new HashMap<String, String>(); Field[] fields = obj.getClass().getDeclaredFields(); for (Field field : fields) { if ("serialVersionUID".equals(field.getName())) { continue; } String dstName = CamelUnderlineUtil.camelToUnderline(field.getName()); PropertyDescriptor pd; pd = new PropertyDescriptor(field.getName(), clazz); Method method = pd.getReadMethod(); Object dstObject = method.invoke(obj); if (dstObject instanceof Date) { dstObject = convertToTimeStamp16((Date) dstObject); } if (dstObject instanceof ArrayList) { dstObject = ""; } dstMap.put(dstName, StringUtil.isEmpty(dstObject) ? "" : dstObject.toString()); } return dstMap; }
标签:else script == row div timestamp 支持 dHash rip
原文地址:https://www.cnblogs.com/lingtiaoti/p/12510055.html