/** * 将info转成entity * @param o * @param c * @param * @return */ public static T createEntity(Object o, Class c){ T obj=null; try { Method[] m1=o.getClass().getMethods(); Method[] m2=c.getMethods(); obj=c.newInstance(); for (Method method : m2) { if (method.getName().startsWith(“set”)) { String n=method.getName().replaceFirst(“set”,”get”); if(isMethodExist(m1,n)){ method.invoke(obj,o.getClass().getMethod(n).invoke(o)); //entity.setName(info.getName()); } } } }catch (Exception e){ e.printStackTrace(); return null; } return obj; } private static boolean isMethodExist(Method[] methods,String methodName){ for (Method method : methods) { if (method.getName().equals(methodName)) { return true; } } return false; }