Springboot两个Bean之间转换import org.springframework.beans.BeansException;
import org.springframework.beans.FatalBeanException;
import org.springframework.util.Assert;
import java.beans.PropertyDescriptor;
springframework和springboot
import flect.Method;
import flect.Modifier;
public class BeanCopyUtils extends org.springframework.beans.BeanUtils{
public static void copyBean(Object source, Object target) throws BeansException {
Class<?> actualEditable = Class();
PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
for (PropertyDescriptor targetPd : targetPds) {
if (WriteMethod() != null) {
PropertyDescriptor sourcePd = Class(), Name());
if (sourcePd != null && ReadMethod() != null) {
try {
Method readMethod = ReadMethod();
if (!Modifier.DeclaringClass().getModifiers())) {
readMethod.setAccessible(true);
}
Object value = readMethod.invoke(source);
if (value != null) {
Method writeMethod = WriteMethod();
if (!Modifier.DeclaringClass().getModifiers())) {
writeMethod.setAccessible(true);
}
writeMethod.invoke(target, value);
}
} catch (Throwable ex) {
throw new FatalBeanException("Could not copy properties from source to target", ex);
}
}
}
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。