ToStringBuilder用法

        //对象及其属性一行显示
        System.out.println(ToStringBuilder.reflectionToString(this));
        System.out.println(ToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE));

        //属性换行显示
        System.out.println(ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE));

        //不显示属性名,只显示属性值,在同一行显示
        System.out.println(ToStringBuilder.reflectionToString(this, ToStringStyle.NO_FIELD_NAMES_STYLE));

        //对象名称简写
        System.out.println(ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE));

        //只显示属性
        System.out.println(ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE));

        结果显示:
-------------ToStringBuilder-------------------------
        test.Bean@141d683[name=zhangsan,age=25]
        
        test.Bean@141d683[name=zhangsan,age=25]
        
        test.Bean@141d683[
          name=zhangsan
          age=25 
        ]
        
        test.Bean@141d683[zhangsan,25]
        
        Bean[name=zhangsan,age=25]
        
        zhengtian,25

 转载https://zheng12tian.iteye.com/blog/1570435

你可能感兴趣的:(ToStringBuilder用法)