两个小方法,用于解决BeanUtils.copyProperties(x, y);中源对象的值为空问题
1.通过实体注解数据库字段为Map的Key,需要的非空值为Value封装数据
@Override
public Map<String, Object> setNodeParamItems(DispatchInfoItem dispatchInfoItem) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Map<String, Object> map = new HashMap<>();
DispatchInfo dispatchInfo = new DispatchInfo();
if (null != dispatchInfoItem) {
BeanUtils.copyProperties(dispatchInfoItem, dispatchInfo);
}
Method[] methods = dispatchInfo.getClass().getDeclaredMethods();
if (methods != null) {
for (Method method : methods) {
String methodName = method.getName();
if (methodName.startsWith("get")) {
Column column = dispatchInfo.getClass().getDeclaredMethod(methodName).getAnnotation(Colum