通用类型转化工具(do->dto)

/**
 * 通用类型转化转换工具类
 *
 * @author Administrator
 */
public class BeanConvertUtils {

    /*
     * 类型转化
     */
    public static final <Target> Target copyProperties(Object source, Class<Target> targetClass) {
        try {
            if (source == null || targetClass == null) {
                return null;
            }
            Target doInstance = targetClass.newInstance();
            BeanUtils.copyProperties(source, doInstance);
            return doInstance;
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

}
posted @ 2019-12-20 10:56  皮肤黝黑的小白  阅读(549)  评论(0)    收藏  举报