org.modelmapper.ModelMapper.map()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中org.modelmapper.ModelMapper.map()方法的一些代码示例,展示了ModelMapper.map()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ModelMapper.map()方法的具体详情如下:
包路径:org.modelmapper.ModelMapper
类名称:ModelMapper
方法名:map

ModelMapper.map介绍

[英]Maps source to an instance of destinationType. Mapping is performed according to the corresponding TypeMap. If no TypeMap exists for source.getClass() and destinationType then one is created.
[中]将源映射到destinationType的实例。根据相应的类型映射执行映射。如果源不存在类型映射。getClass()和destinationType,然后创建一个。

代码示例

代码示例来源:origin: Raysmond/SpringBlog

public static <S, T> List<T> mapList(List<S> source, Class<T> targetClass) {
    List<T> list = new ArrayList<>();
    for (S s : source) {
      list.add(getMapper().map(s, targetClass));
    }
    return list;
  }
}

代码示例来源:origin: Raysmond/SpringBlog

public static <S, T> T map(S source, Class<T> targetClass) {
  return getMapper().map(source, targetClass);
}

代码示例来源:origin: Raysmond/SpringBlog

public static <S, T> void mapTo(S source, T dist) {
  getMapper().map(source, dist);
}

代码示例来源:origin: Vedenin/useful-java-links

public static void main(String[] args) {
    // init mapper
    PropertyMap<Source, Destination> orderMap = new PropertyMap<Source, Destination>() {
      protected void configure() {
        map().setText(source.getMessage());
      }
    };
    ModelMapper modelMapper = new ModelMapper();
    modelMapper.addMappings(orderMap);

    // convert
    Source source = new Source("Hello World!");
    Destination destObject = modelMapper.map(source, Destination.class);
    destObject.print(); // print Hello World!
  }
}

代码示例来源:origin: bramp/ffmpeg-cli-wrapper

public static <T extends AbstractFFmpegStreamBuilder<T>> void map(
  MainEncodingOptions opts, AbstractFFmpegStreamBuilder<T> dest) {
 mapper.map(opts, dest);
}

代码示例来源:origin: bramp/ffmpeg-cli-wrapper

public static <T extends AbstractFFmpegStreamBuilder<T>> void map(
  VideoEncodingOptions opts, AbstractFFmpegStreamBuilder<T> dest) {
 mapper.map(new VideoWrapper(opts), dest);
}

代码示例来源:origin: bramp/ffmpeg-cli-wrapper

public static <T extends AbstractFFmpegStreamBuilder<T>> void map(
  AudioEncodingOptions opts, AbstractFFmpegStreamBuilder<T> dest) {
 mapper.map(new AudioWrapper(opts), dest);
}

代码示例来源:origin: hantsy/angularjs-springmvc-sample-boot

public static <S, T> List<T> mapList(List<S> source, Class<T> targetClass) {
  List<T> list = new ArrayList<>();
  for (int i = 0; i < source.size(); i++) {
    T target = INSTANCE.map(source.get(i), targetClass);
    list.add(target);
  }
  return list;
}

代码示例来源:origin: org.apache.archiva/archiva-repository-admin-default

protected NetworkProxy getNetworkProxy( NetworkProxyConfiguration networkProxyConfiguration )
{
  return networkProxyConfiguration == null
    ? null
    : getModelMapper().map( networkProxyConfiguration, NetworkProxy.class );
}

代码示例来源:origin: org.apache.archiva/archiva-repository-admin-default

protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector )
{
  return proxyConnector == null
    ? null
    : getModelMapper().map( proxyConnector, ProxyConnectorConfiguration.class );
}

代码示例来源:origin: org.seedstack.addons.modelmapper/modelmapper

@Override
public void mergeAggregateIntoDto(T sourceAggregate, D targetDto) {
  ModelMapper modelMapper = getModelMapper();
  for (Object o : sourceAggregate) {
    modelMapper.map(o, targetDto);
  }
}

代码示例来源:origin: org.seedstack.addons.modelmapper/modelmapper

@Override
public void mergeDtoIntoAggregate(D sourceDto, T targetAggregate) {
  ModelMapper modelMapper = getModelMapper();
  for (Object o : targetAggregate) {
    modelMapper.map(sourceDto, o);
  }
}

代码示例来源:origin: org.seedstack.addons.modelmapper/modelmapper

@Override
public D createDtoFromAggregate(T sourceAggregate) {
  D sourceDto = null;
  ModelMapper modelMapper = getModelMapper();
  for (Object o : sourceAggregate) {
    if (sourceDto == null) {
      sourceDto = modelMapper.map(o, getDtoClass());
    }
    modelMapper.map(o, sourceDto);
  }
  return sourceDto;
}

代码示例来源:origin: ConsenSys/eventeum

public Web3jLog(org.web3j.protocol.core.methods.response.Log web3jLog) {

    final ModelMapper modelMapper = ModelMapperFactory.getInstance().createModelMapper();
    modelMapper.map(web3jLog, this);
  }
}

代码示例来源:origin: ldlqdsdcn/eidea4

@Override
public List<PageMenuBo> findPageMenu(Search search) {
  List<PageMenuPo> pageMenuPoList = pageMenuDao.search(search);
  List<PageMenuBo> PageMenuBoList = modelMapper.map(pageMenuPoList, new TypeToken<List<PageMenuBo>>() {
  }.getType());
  return PageMenuBoList;
}
@Override

代码示例来源:origin: ldlqdsdcn/eidea4

@Override
public List<UserSessionBo> getUserSessionList(Search search) {
  List<UserSessionBo> userSessionBoList = new ArrayList<UserSessionBo>();
  List<UserSessionPo> userSessionPoList = userSessionDao.search(search);
  for (UserSessionPo up : userSessionPoList) {
    UserSessionBo u = modelMapper.map(up, UserSessionBo.class);
    u.setUsername(up.getUserPo().getUsername());
    userSessionBoList.add(u);
  }
  return userSessionBoList;
}

代码示例来源:origin: getheimdall/heimdall

/**
* Converts a source to a type destination.
* 
* @param source                    The source object
* @param typeDestination            The type destination
* @return                            The object created
*/
public static <T, E> E mapper(T source, Class<E> typeDestination) {
  ModelMapper modelMapper = new ModelMapper();
  modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
  return modelMapper.map(source, typeDestination);
}

代码示例来源:origin: hantsy/angularjs-springmvc-sample-boot

public static <S, T> Page<T> mapPage(Page<S> source, Class<T> targetClass) {
    List<S> sourceList = source.getContent();

    List<T> list = new ArrayList<>();
    for (int i = 0; i < sourceList.size(); i++) {
      T target = INSTANCE.map(sourceList.get(i), targetClass);
      list.add(target);
    }

    return new PageImpl<>(list, new PageRequest(source.getNumber(), source.getSize(), source.getSort()),
        source.getTotalElements());
  }
}

代码示例来源:origin: ldlqdsdcn/eidea4

@Override
  public List<ModuleDirectoryBo> getModuleDirectoryList(int directoryId) {
    Search search=new Search();
    search.addFilterEqual("sysDirectory.id",directoryId);
    search.addSortAsc("id");
    List<ModuleDirectoryPo> moduleDirectoryAllList=moduleDirectoryDao.search(search);
    return modelMapper.map(moduleDirectoryAllList,new TypeToken<List<ModuleDirectoryBo>>(){}.getType());
  }
}

代码示例来源:origin: ldlqdsdcn/eidea4

@Override
public void save(OrgBo orgBo) {
  ClientPo clientPo = clientDao.find(orgBo.getClient().getId());
  OrgPo orgPo = modelMapper.map(orgBo, OrgPo.class);
  orgPo.setSysClient(clientPo);
  orgDao.saveForLog(orgPo);
  orgBo.setId(orgPo.getId());
}

相关文章