打印类工具ReflectionToStringBuilder

http://www.oschina.net/code/snippet_55970_16171

  public String toString(){
        ReflectionToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
//去掉不需要打印出的属性 使用正则去掉类名和【】
       return  ReflectionToStringBuilder.toStringExclude(this,"memberId","userId","regDate",
               "unregDate","memberStatus").replaceAll("(\\w+\\[)|\\]","");
    }



public static String toString(Object obj){
        return toString(obj, ToStringStyle.MULTI_LINE_STYLE);
    }

    public static String toString(Object obj, ToStringStyle stringStyle){
        return ReflectionToStringBuilder.toString(obj, stringStyle);
    }

猜你喜欢

转载自panyongzheng.iteye.com/blog/2261041
今日推荐