反射的2种方法
    1.

    1. /**<br /> * Javabean转为map<br /> *<br /> * @param bean<br /> * @return<br /> * @throws Exception<br /> */<br /> public static Map<String, Object> bean2map(Object bean) throws Exception {<br /> Map<String, Object> map = new HashMap<>();<br /> //获取指定类(Person)的BeanInfo 对象<br /> **BeanInfo** beanInfo = Introspector.getBeanInfo(bean.getClass());<br /> //获取所有的属性描述器<br /> ** PropertyDescriptor[] **pds = beanInfo.getPropertyDescriptors();<br /> for (PropertyDescriptor pd : pds) {<br /> String key = pd.getName();<br /> Method getter = pd.getReadMethod();<br /> Object value = getter.invoke(bean);<br /> map.put(key, value);<br /> }<br /> return map;<br /> }<br /> <br />2.t = (T)list.get(i);<br />if(t.getClass().getName().equals("java.util.HashMap")){<br />Object obj = ((Map)t).get(entry.getValue().toString());<br />if(obj.toString().equals("0E-10")) {<br /> stringBuilder.append("0");<br /> stringBuilder.append(",");<br />}<br />else {<br /> stringBuilder.append(obj == null ? "" :obj);<br /> stringBuilder.append(",");<br />}<br />} else {<br />**//feild,是反射**<br />**Field** field = t.getClass().getDeclaredField(entry.getValue().toString());<br />//设置对象的访问权限,保证对private的属性的访问<br />field.setAccessible(true);<br />stringBuilder.append(field.get(t) == null ? "" : field.get(t));<br />stringBuilder.append(",");<br /> }