Dozer DO与VO转换(List)

Dozer只支持Class转换,不支持List-to-List。以下代码块用于List转换。

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

import org.dozer.Mapper;

public class DozerUtils {

    /**
     * Encapsulate the method of dozer processing set: List < s > > > < T > List
     */
    public static <T, S> List<T> mapList(final Mapper mapper, List<S> sourceList, Class<T> targetObjectClass) {
        List<T> targetList = new ArrayList<T>();
        for (S s : sourceList) {
            targetList.add(mapper.map(s, targetObjectClass));
        }
        return targetList;
    }
}
posted @ 2022-04-14 23:49  中二越  阅读(317)  评论(0编辑  收藏  举报