/** * 将任意vo转化成map * * @param t vo对象 * @return */ private <T> Map<String, Object> convert2Map(T t){ Map<String, Object> result = new HashMap<String, Object>(); Method[] methods = t.getClass().getMethods(); try { for (Method method : methods) { Class<?>[] paramClass = method.getParameterTypes(); if (paramClass.length > 0) { // 如果方法带参数,则跳过 continue; } String methodName = method.getName() ; if (methodName.startsWith("get")) { Object value = method.invoke(t); result.put(methodName, value); } } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } return result; }