package com.sinosoft.prd.calc.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
/**
* @Description: 对象字段赋值、取值工具类
* @Author: c
* @DateTime: 2023/8/21 10:22
*/
public class ClassFiledUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ClassFiledUtils.class);
/**
* 通过对象的属性名称赋值
*
* @param o 目标对象
* @param fieldName 字段名称
* @param value 值
* @return DutyPremDTO
*/
public static Object setFieldValue(Object o, String fieldName, Object value) {
try {
Field field = o.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
field.set(o, value);
} catch (Exception e) {
LOGGER.error("发生错误: ", e);
}
return o;
}
/**
* 根据对象和字符串类型的属性名称获取对应属性的值
*
* @param target 目标对象
* @param fieldName 属性名称
* @return Object
*/
public static Object getFieldValue(Object target, String fieldName) {
Field field;
try {
//获取字段名称
field = target.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(target);
} catch (NoSuchFieldException | IllegalAccessException e) {
LOGGER.error("发生异常: ", e);
}
return null;
}
}
plsql 下载地址 https://www.allroundautomations.com/registered-plsqldev/