你也可以使用A帮助器类在一个步骤中做到这一点
public class DozerHelper {
public static <T, U> ArrayList<U> map(final Mapper mapper, final List<T> source, final Class<U> destType) {
final ArrayList<U> dest = new ArrayList<U>();
for (T element : source) {
if (element == null) {
continue;
}
dest.add(mapper.map(element, destType));
}
// finally remove all null values if any
List s1 = new ArrayList();
s1.add(null);
dest.removeAll(s1);
return dest;
}
}
你上面的电话会像
List<ClassB> listB = DozerHelper.map(mapper, variableListClassA, ClassB.class);