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

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

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

ModelMapper.addMappings介绍

[英]Adds mappings from the propertyMap into the TypeMap corresponding to source type S and destination type D. Explicit mappings defined in the propertyMapwill override any implicit mappings for the same properties.
[中]将propertyMap中的映射添加到与源类型S和目标类型D相对应的TypeMap中。propertyMap中定义的显式映射将覆盖相同属性的任何隐式映射。

代码示例

代码示例来源: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: ldlqdsdcn/eidea4

public SearchServiceImpl()
{
  modelMapper.addMappings(new PropertyMap<SearchColumnPo, SearchColumnBo>() {
    @Override
    protected void configure() {
      map().setLabelKey(source.getCoreLabel().getKey());
    }
  });
}
@Override

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

public LanguageServiceImpl() {
  modelMapper.addMappings(langTrlMapper);
  modelMapper.addMappings(languageBoPropertyMap);
}

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

public LabelServiceImpl() {
  modelMapper.addMappings(new PropertyMap<LabelTrlPo, LabelTrlBo>() {
    @Override
    protected void configure() {
      map().setLang(source.getLanguagePo().getCode());
    }
  });
}

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

public MessageServiceImpl() {
  modelMapper.addMappings(messageBoPropertyMap);
  modelMapper.addMappings(messageTrlBoPropertyMap);
}

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

public RoleServiceImpl() {
  modelMapper.addMappings(new PropertyMap<RoleOrgaccessPo, RoleOrgaccessBo>() {
    @Override
    protected void configure() {
      map().setOrgId(source.getSysOrg().getId());
      map().setChecked(true);
      map().setOrgName(source.getSysOrg().getName());
      map().setRoleId(source.getSysRole().getId());
      map().setRoleName(source.getSysRole().getName());
    }
  });
  modelMapper.addMappings(new PropertyMap<ModuleRolePo, ModuleRoleBo>() {
    @Override
    protected void configure() {
      map().setRoleId(source.getSysRole().getId());
      map().setRoleName(source.getSysRole().getName());
      map().setModuleId(source.getSysModule().getId());
      map().setModuleName(source.getSysModule().getName());
    }
  });
  modelMapper.addMappings(new PropertyMap<PrivilegesPo, PrivilegeBo>() {
    @Override
    protected void configure() {
      map().setChecked(true);
      map().setModuleRoleId(source.getSysModuleRole().getId());
      map().setOperatorId(source.getSysOperator().getId());
      map().setOperatorName(source.getSysOperator().getName());
    }
  });
}

代码示例来源:origin: arey/java-object-mapper-benchmark

public ModelMapper() {
  modelMapper = new org.modelmapper.ModelMapper();
  modelMapper.addMappings(new PropertyMap<Order, OrderDTO>() {
    @Override
    protected void configure() {
      map().setBillingStreetAddress(source.getCustomer().getBillingAddress().getStreet());
      map().setBillingCity(source.getCustomer().getBillingAddress().getCity());
      map().setShippingStreetAddress(source.getCustomer().getShippingAddress().getStreet());
      map().setShippingCity(source.getCustomer().getShippingAddress().getCity());
    }
  });
}

代码示例来源:origin: jmnarloch/modelmapper-spring-boot-starter

/**
   * Configures the passed {@link ModelMapper} instance by registering the {@link PropertyMap} defined by
   * {@link #mapping()} method.
   *
   * @param modelMapper {@link ModelMapper} instance to be configured
   */
  @Override
  public void configure(ModelMapper modelMapper) {

    modelMapper.addMappings(mapping());
  }
}

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

public TableServiceImpl() {
  modelMapper = new ModelMapper();
  modelMapper.addMappings(languageBoPropertyMap);
}

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

/**
* Converts a source to a type destination.
* 
* @param source                The souce object
* @param typeDestination        The type destination 
* @param mapping                The properties for the mapping process
* @return                        The object created
*/
public static <T, E> E mapperWithMapping(T source, Class<E> typeDestination, PropertyMap<T, E> mapping) {
  ModelMapper modelMapper = new ModelMapper();
  modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
  modelMapper.addMappings(mapping);
  return modelMapper.map(source, typeDestination);
}

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

/**
* Converts a source to a type destination.
* 
* @param source                The souce object
* @param destination            The destination object
* @param mapping                The properties for the mapping process
* @return                        The object created
*/
public static <T, E> E mapperWithMapping(T source, E destination, PropertyMap<T, E> mapping) {
  
  ModelMapper modelMapper = new ModelMapper();
  modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
  modelMapper.addMappings(mapping);
  modelMapper.map(source, destination);
  
  return destination; 
}

代码示例来源:origin: stackoverflow.com

public class User {
  @Id
  private long id;

  private String email;

  @XmlTransient
  private String password;
  ...
}

public class UserService {
  ...
  public User updateUser(User dto) {
    User entity = em.find(User.class, dto.getId());
    ModelMapper modelMapper = new ModelMapper();
    modelMapper.addMappings(new UserMap());
    modelMapper.map(userDto, user);
    return user;
  }
}

public class UserMap extends PropertyMap<User, User> {
  protected void configure() {
    skip().setPassword(null);
  }
}

代码示例来源:origin: stackoverflow.com

mapper.addMappings(new PropertyMap<SrcClass, DestClass>() {
  @Override
  protected void configure() {

相关文章