Compartilhe uma classe de clone de atributo de objeto JavaBean, super fácil de usar

Um, a parte do código

Compartilhe uma classe de clone de atributo de objeto JavaBean, diretamente no código:

package com.standard.commonutil.util;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 * 对象属性克隆类
 * </pre>
 */
public class BeanClone {
    
    

    public static <T, K> K clone(T po, Class<K> clz) {
    
    
        try {
    
    
            if (po != null) {
    
    
                K k = clz.newInstance();
                PropertyClone.copyProperties(k, po, true);
                return k;
            }
        } catch (Exception ex) {
    
    
            throw new RuntimeException(ex.getMessage());
        }
        return null;
    }

    public static <T, K> List<K> clone(List<T> tlist, Class<K> clz) {
    
    
        List<K> klist = new ArrayList<K>();
        if (tlist != null && tlist.size() > 0) {
    
    
            for (T t : tlist) {
    
    
                klist.add(clone(t, clz));
            }
        }
        return klist;
    }
}

Em segundo lugar, use exemplos

//用origEngity的属性生成一个新的NewClass类型的JavaBean
BeanClone.clone(origEngity, NewClass.getClass());

Tres enfim

Se você não quiser aceitar, dê uma recompensa. Se você não der uma recompensa, pelo menos preste atenção no blogueiro, haha, haha, hehe.

Acho que você gosta

Origin blog.csdn.net/datuanyuan/article/details/109101115
Recomendado
Clasificación