Skip to content

Commit

Permalink
增加mapper对象映射方法
Browse files Browse the repository at this point in the history
  • Loading branch information
honyma committed Aug 7, 2020
1 parent 51a839a commit cf5ccb5
Showing 1 changed file with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,50 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* 实体熟悉映射工具
*/
public abstract class BeanMapperUtils {

private static MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
private static MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

public static <S, D> D map(S source, Class<D> clazz) {
if (source == null) {
return null;
}
public static <S, D> D map(S source, Class<D> clazz) {
if (Objects.isNull(source)) {
return null;
}

MapperFacade mapper = mapperFactory.getMapperFacade();
return mapper.map(source, clazz);
}
MapperFacade mapper = mapperFactory.getMapperFacade();
return mapper.map(source, clazz);
}

public static <S, D> D map(S s, Type<S> sType, Type<D> dType) {
if (s == null) {
return null;
}
public static <S, D> void map(S source, D destination) {
if (Objects.isNull(source) || Objects.isNull(destination)) {
return;
}

MapperFacade mapper = mapperFactory.getMapperFacade();
return mapper.map(s, sType, dType);
}
MapperFacade mapper = mapperFactory.getMapperFacade();
mapper.map(source, destination);
}

public static <S, D> List<D> mapAsList(List<S> source, Class<D> clazz) {
if (CollectionUtil.isEmpty(source)) {
return Collections.emptyList();
}
public static <S, D> D map(S s, Type<S> sType, Type<D> dType) {
if (s == null) {
return null;
}

MapperFacade mapper = mapperFactory.getMapperFacade();
return mapper.mapAsList(source, clazz);
}
MapperFacade mapper = mapperFactory.getMapperFacade();
return mapper.map(s, sType, dType);
}

public static <S, D> List<D> mapAsList(List<S> source, Class<D> clazz) {
if (CollectionUtil.isEmpty(source)) {
return Collections.emptyList();
}

MapperFacade mapper = mapperFactory.getMapperFacade();
return mapper.mapAsList(source, clazz);
}


}

0 comments on commit cf5ccb5

Please sign in to comment.