public static void main(String[] args) {
public Result<String> information(info req) {
Map<String,Object> map =new HashMap<>();
Map<String, String> fieldValueMap = new HashMap<>();
Field[] fields = req.getClass().getDeclaredFields();//获取私有字段
for (int i = 0; i < fields.length; i++) {
try {
//设置是否允许访问,不是修改原来的访问权限修饰词。
fields[i].setAccessible(true);
String fieldTitle = fields[i].getName();//字段名
String fieldValue = (String) fields[i].get(req);//字段值
Object ob = map.get(fieldTitle);
if(ob == null){
continue;
}
int judgeStatus = (int) ob; //需要判断的值
if (judgeStatus == 3) {
throw new GlobalException(EnumStatusCode.ENTERPRISE_INFO);
}
if(judgeStatus == 2){
flag = true;
}
if (judgeStatus > 0 && StringUtils.isNotBlank(fieldValue)){
fieldValueMap.put(fieldTitle,fieldValue);//过滤出会走审核的字段
}
} catch (Exception e) {
continue;
}
}
}
通过前端传的类值 进行java反射获取字段值
最新推荐文章于 2024-04-16 08:31:26 发布