下面代码主要是为了将空字符串赋值成null
//处理空字符串
private void setNull(Collection<?> objectList) {
objectList.forEach(x -> {
Class<?> aClass = x.getClass();
try {
Field[] fields = aClass.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
// 得到此属性的值
Object checkField = field.get(x);
if(checkField instanceof String && ObjectUtils.isEmpty(checkField)) {
field.set(x, null);
}
}
} catch (Exception e) {
}
});
}