package com.shkpr.service.alambizplugin.commtools; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.BeanUtils; /** * bean工具类 * * @author 欧阳劲驰 * @since 1.0.0 */ public class BeanUtil { /** * 拷贝 * * @param source 被拷贝对象 * @param targetType 类型 * @param 类型 * @return 新对象 */ public static T copy(Object source, Class targetType) { try { if (!ObjectUtils.allNotNull(source, targetType)) { return null; } //拷贝资源 T t = targetType.getDeclaredConstructor().newInstance(); BeanUtils.copyProperties(source, t); return t; } catch (ReflectiveOperationException e) { return null; } } }