common_helper/src/main/java/com/xiongyingqi/util/PrintHelper.java
public String reflectToString(Object object) {
        if (object == null) {
            return null;
        }
        Class clazz = object.getClass();

        StringBuilder builder = new StringBuilder(clazz.getName());
        builder.append("@");
        builder.append(Integer.toHexString(object.hashCode()));
        builder.append("[");

        Set<Method> methods = new LinkedHashSet<Method>();

        Collection<Class> classes = EntityHelper.getAllSuperClassesOfClass(clazz);
        for (Iterator iterator = classes.iterator(); iterator.hasNext(); ) {
            Class claxx = (Class) iterator.next();
            Method[] clazzMethods = claxx.getDeclaredMethods();
            for (int i = 0; i < clazzMethods.length; i++) {
                Method method = clazzMethods[i];
                methods.add(method);
            }
        }

        // for (int i = 0; i < methods.length; i++) {
        // Method method = methods[i];
        for (Iterator iterator = methods.iterator(); iterator.hasNext(); ) {
            Method method = (Method) iterator.next();
            String methodName = method.getName();
            if (methodName.startsWith("get") && !Modifier.isStatic(method.getModifiers())
                    && Modifier.isPublic(method.getModifiers())) {
                try {
                    Object value = method.invoke(object);
                    String propertyName = methodName.substring(3, 4).toLowerCase()
                            + methodName.substring(4);
                    if (propertyName.equals("class") || ignoreProperties.contains(propertyName)) {// 忽略getClass方法
                        continue;
                    }
                    builder.append(propertyName);
                    builder.append("=");

                    if (value == null) {
                        builder.append("<null>");
                    } else {
                        if (value.getClass().isArray()) {
                            int arraySuperLength = Array.getLength(value);
                            builder.append("{");
                            for (int j = 0; j < arraySuperLength; j++) {
                                Object object2 = Array.get(value, j);
                                builder.append(object2.toString());
                                if (j < arraySuperLength - 1) {
                                    builder.append(", ");
                                }
                            }
                            builder.append("}");
                        } else {
                            builder.append(value.toString());
                        }
                    }
                    builder.append(", ");
                } catch (IllegalArgumentException e) {
                } catch (IllegalAccessException e) {
                } catch (InvocationTargetException e) {
                }
            }
        }

        if (builder.toString().contains(", ")) {
            builder.replace(builder.length() - 2, builder.length(), "");
        }

        builder.append("]");
        return builder.toString();
    }
public String reflectToString(Object object) {
        if (object == null) {
            return null;
        }
        Class clazz = object.getClass();

        StringBuilder builder = new StringBuilder(clazz.getName());
        builder.append("@");
        builder.append(Integer.toHexString(object.hashCode()));
        builder.append("[");

        Set<Method> methods = new LinkedHashSet<Method>();

        Collection<Class> classes = EntityHelper.getAllSuperClassesOfClass(clazz);
        for (Iterator iterator = classes.iterator(); iterator.hasNext(); ) {
            Class claxx = (Class) iterator.next();
            Method[] clazzMethods = claxx.getDeclaredMethods();
            for (int i = 0; i < clazzMethods.length; i++) {
                Method method = clazzMethods[i];
                methods.add(method);
            }
        }

        // for (int i = 0; i < methods.length; i++) {
        // Method method = methods[i];
        for (Iterator iterator = methods.iterator(); iterator.hasNext(); ) {
            Method method = (Method) iterator.next();
            String methodName = method.getName();
            if (methodName.startsWith("get") && !Modifier.isStatic(method.getModifiers())
                    && Modifier.isPublic(method.getModifiers())) {
                try {
                    Object value = method.invoke(object);
                    String propertyName = methodName.substring(3, 4).toLowerCase()
                            + methodName.substring(4);
                    if (propertyName.equals("class") || ignoreProperties.contains(propertyName)) {// 忽略getClass方法
                        continue;
                    }
                    builder.append(propertyName);
                    builder.append("=");

                    if (value == null) {
                        builder.append("<null>");
                    } else {
                        if (value.getClass().isArray()) {
                            int arraySuperLength = Array.getLength(value);
                            builder.append("{");
                            for (int j = 0; j < arraySuperLength; j++) {
                                Object object2 = Array.get(value, j);
                                builder.append(object2.toString());
                                if (j < arraySuperLength - 1) {
                                    builder.append(", ");
                                }
                            }
                            builder.append("}");
                        } else {
                            builder.append(value.toString());
                        }
                    }
                    builder.append(", ");
                } catch (IllegalArgumentException e) {
                } catch (IllegalAccessException e) {
                } catch (InvocationTargetException e) {
                }
            }
        }

        if (builder.toString().contains(", ")) {
            builder.replace(builder.length() - 2, builder.length(), "");
        }

        builder.append("]");
        return builder.toString();
    }
使用反射机制自动ToString <br>
2013-8-28 下午3:16:40

@param object
@return