package com.subsidy.util; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import java.beans.PropertyDescriptor; import java.util.HashSet; import java.util.Set; public class MyBeanUtils { public static String[] getNullPropertyNames (Object source) { final BeanWrapper src = new BeanWrapperImpl(source); PropertyDescriptor[] pds = src.getPropertyDescriptors(); Set<String> emptyNames = new HashSet<>(); for(PropertyDescriptor pd : pds) { Object srcValue = src.getPropertyValue(pd.getName()); // 此处判断可根据需求修改 if (srcValue == null) { emptyNames.add(pd.getName()); } } String[] result = new String[emptyNames.size()]; return emptyNames.toArray(result); } }