获取对象Spring Boot Java的属性值
如何获取打印在图像上的变量statusCode获取对象Spring Boot Java的属性值,java,spring-boot,Java,Spring Boot,如何获取打印在图像上的变量statusCode Object obj = pjp.proceed(); for (Field field : obj.getClass().getDeclaredFields()) { field.setAccessible(true); Object value = field.get(obj); if (value != null) {
Object obj = pjp.proceed();
for (Field field : obj.getClass().getDeclaredFields()) {
field.setAccessible(true);
Object value = field.get(obj);
if (value != null) {
System.out.println(field.getName() + " = " + value);
//Print: presSvcRs = banckofcolombia.checkinvoice.IFX$PresSvcRs@107813f5
}
如果IFX类使用getter公开其字段,则可以执行以下操作,而不是使用反射访问字段:
Object obj = pjp.proceed();
if(obj instanceof IFX) {
IFX ifx = (IFX) obj;
String statusCode = obj.getPresSvcRs().getBillInqRs().getStatus().getStatusCode();
}
如果您可以将obj强制转换为IFX类而不是使用反射,那么您的代码将更加健壮。也许IFX类有状态码的访问器?