1234567891011121314151617181920212223242526272829303132333435 |
- 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 <T> 类型
- * @return 新对象
- */
- public static <T> T copy(Object source, Class<T> 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;
- }
- }
- }
|