在 java 中打印 bean 对象
Print bean object in java
我尝试如下打印一个 bean 对象。
CNSLResponseInfo csnlObject = new CNSLResponseInfo();
System.out.println(csnlObject .toString());
输出如下。
org.omo.model.CNSLResponseInfo@59d7305f
如有任何建议,我们将不胜感激。
谢谢你
由于您没有验证 toString()
,它会调用您需要验证的默认实现 toString()
并提供您自己的实现。
现在它正在打印 Object class toString()
方法的默认实现,该方法以提供对象哈希码的 unsigned hexadecimal
表示的方式实现。
开始阅读What is the best standard style for a toString implementation?
您必须覆盖 CNSLResponseInfo
class 中的 toString
方法。
覆盖classCNSLResponseInfo
的.toString()
方法然后调用System.out.println(csnlObject);
@Override
public String toString() {
return prop1 + ", " + prop2 + ", " + prop3;
}
您需要覆盖 CNSLResponseInfo 中的 toString() class。没有它,调用对象class toString(),实现为return FullyQualifiedClassName@Hashcode
我尝试如下打印一个 bean 对象。
CNSLResponseInfo csnlObject = new CNSLResponseInfo();
System.out.println(csnlObject .toString());
输出如下。
org.omo.model.CNSLResponseInfo@59d7305f
如有任何建议,我们将不胜感激。
谢谢你
由于您没有验证 toString()
,它会调用您需要验证的默认实现 toString()
并提供您自己的实现。
现在它正在打印 Object class toString()
方法的默认实现,该方法以提供对象哈希码的 unsigned hexadecimal
表示的方式实现。
开始阅读What is the best standard style for a toString implementation?
您必须覆盖 CNSLResponseInfo
class 中的 toString
方法。
覆盖classCNSLResponseInfo
的.toString()
方法然后调用System.out.println(csnlObject);
@Override
public String toString() {
return prop1 + ", " + prop2 + ", " + prop3;
}
您需要覆盖 CNSLResponseInfo 中的 toString() class。没有它,调用对象class toString(),实现为return FullyQualifiedClassName@Hashcode