增加美甲师认证审核逻辑
修改了管理员修改美甲师信息时空字符串会覆盖原来信息的问题
This commit is contained in:
parent
5dffc7aee1
commit
d3b6383e47
|
@ -0,0 +1,36 @@
|
||||||
|
package com.cj.jiaqingjiayi.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.BeanWrapper;
|
||||||
|
import org.springframework.beans.BeanWrapperImpl;
|
||||||
|
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class BeanCopyUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拷贝属性,跳过 null 和空字符串
|
||||||
|
*/
|
||||||
|
public static void copyPropertiesIgnoreEmpty(Object source, Object target) {
|
||||||
|
BeanUtils.copyProperties(source, target, getNullOrEmptyPropertyNames(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取属性值为 null 或空字符串的属性名
|
||||||
|
*/
|
||||||
|
private static String[] getNullOrEmptyPropertyNames(Object source) {
|
||||||
|
final BeanWrapper src = new BeanWrapperImpl(source);
|
||||||
|
PropertyDescriptor[] pds = src.getPropertyDescriptors();
|
||||||
|
|
||||||
|
Set<String> emptyNames = new HashSet<>();
|
||||||
|
for (PropertyDescriptor pd : pds) {
|
||||||
|
Object value = src.getPropertyValue(pd.getName());
|
||||||
|
if (value == null || "".equals(value)) {
|
||||||
|
emptyNames.add(pd.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return emptyNames.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user