【JAVA】反射获取对象LIST中对象属性
背景
照着这篇⽂章敲了⼀下例⼦,然后有⼀些需要注意的地⽅,这⾥记录⼀下。
代码
⾸先是需要引⼊的依赖项,如下:日本留学咨询
implementation 'org.asrtj:asrtj-core:3.21.0'
implementation 'org.springframework:spring-aspects:5.3.13'
implementation 'com.github.ulisbocchio:jasypt-spring-boot-starter:3.0.4'
implementation 'com.alibaba:fastjson:1.2.78'
implementation 'com.:jackson-databind:2.13.0'
2011广东高考分数线
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework:spring-aop:5.3.14'
配置⽂件⾥还需要配置⼀下:
研究生预报名是什么意思
然后其他代码看原博客就可以。
gment是什么意思改进
这⾥主要写⼀下,改动了的地⽅,也就是EncryptHandler的handler⽅法,因为这个handler⽅法这能处理参数或者返回值为具体对象,也就是UrVo的情况,处理不了List<UrVo>的情况,下⾯直接上上代码:
private Object handler(Object obj, EncryptConstant type)throws IllegalAccessException {
if(Objects.isNull(obj)){
return null;
}
//判断是否是list
Class cls2 = Class();
estimatesif(cls2.isAssignableFrom(ArrayList.class)
||cls2.isAssignableFrom(List.class)
国外成人聊天室||cls2.isAssignableFrom(LinkedList.class)){
List<Object> list=(List<Object>) obj;
list.forEach(object->{
try{
processObj(object,type);quantitative
}catch(IllegalAccessException e){
e.printStackTrace();
}
});
}el{
processObj(obj,type);
}
return obj;
}
private void processObj(Object obj, EncryptConstant type)throws IllegalAccessException { Field[] fields = Class().getDeclaredFields();
for(Field field : fields){
boolean hasSecureField = field.isAnnotationPrent(EncryptField.class);
if(hasSecureField){交通拥挤 英语
field.tAccessible(true);polartec
String realValue =(String) (obj);
String value;
if(DECRYPT.equals(type)){
value = stringEncryptor.decrypt(realValue);
}el{
value = pt(realValue);
}
field.t(obj, value);
}
}
}
>genie in a bottle