我有以下建议代码:
@Around("annotatedMethod()")
public Object aroundGetPanel(ProceedingJoinPoint joinPoint) throws Throwable
{
Object result = joinPoint.proceed();
return result;
}
执行上述方法的方法是:
public Person getPerson(String id){
return new Person(1,"Maialen");
}
public class Person {
private Integer id = null;
private String name = null;
public Person(Integer id,String name){
this.setId(id);
this.setName(name);
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return nombre;
}
public void setName(String name) {
this.name = name;
}
}
如何获得对象结果(人)的参数?
使用反射?使用注释?
最佳答案
我发现了如何通过反射来做到这一点:
Class<?> clazz = result.getClass();
Field field = org.springframework.util.ReflectionUtils.findField(clazz, "name");
org.springframework.util.ReflectionUtils.makeAccessible(field);
String name=field.get(result).toString();
但是我更喜欢通过注释来实现。有模式吗?