本文整理汇总了Java中org.modelmapper.Converter类的典型用法代码示例。如果您正苦于以下问题:Java Converter类的具体用法?Java Converter怎么用?Java Converter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Converter类属于org.modelmapper包,在下文中一共展示了Converter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: ProductMapper
import org.modelmapper.Converter; //导入依赖的package包/类
public ProductMapper() {
// Converters for complex field conversions
// Converter<LocalDate, LocalDateTime> convertLocalDate2LocalDateTime = context -> context.getSource() == null ? null :
// context.getSource().atStartOfDay();
// Converter<LocalDateTime, LocalDate> convertLocalDateTime2LocalDate = context -> context.getSource() == null ? null :
// context.getSource().toLocalDate();
Converter<List<Category>, List<String>> convertCategory2Name = context -> context.getSource() == null ? null :
context.getSource().stream().map(Category::getName).collect(Collectors.toList());
Converter<List<String>, List<Category>> convertCategoryName2Category = context -> context.getSource() == null ? null :
context.getSource().stream().map((name) -> Category.builder().name(name).build()).collect(Collectors.toList());
// create PropertyMap<source,target> here and add to mapper
// map().set<Target>(source.get<Source>());
// map(source.get<Source>(), destination.get<Target>());
mapper.addMappings(new PropertyMap<Product, ProductDto>() {
@Override
protected void configure() {
using(convertCategory2Name).map(source.getCategories(), destination.getCategory());
}
});
mapper.addMappings(new PropertyMap<ProductDto, Product>() {
@Override
protected void configure() {
using(convertCategoryName2Category).map(source.getCategory(), destination.getCategories());
}
});
}
开发者ID:roybailey,项目名称:research-graphql,代码行数:27,代码来源:ProductMapper.java
示例2: userMapping
import org.modelmapper.Converter; //导入依赖的package包/类
@Bean
public ConverterConfigurer<ProdType, ProdTypeDto> userMapping() {
return new ConverterConfigurer<ProdType, ProdTypeDto>() {
@Override
public Converter<ProdType, ProdTypeDto> converter() {
return new AbstractConverter<ProdType, ProdTypeDto>() {
@Override
protected ProdTypeDto convert(ProdType source) {
switch (source) {
case T1:
return ProdTypeDto.TYPE1;
case T2:
return ProdTypeDto.TYPE2;
}
return null;
}
};
}
};
}
开发者ID:rozidan,项目名称:modelmapper-spring-boot-starter,代码行数:21,代码来源:ConverterConfigurerTest.java
示例3: bcryptConverter
import org.modelmapper.Converter; //导入依赖的package包/类
private Converter<String, String> bcryptConverter() {
return mappingContext -> encoder.encode(mappingContext.getSource());
}
开发者ID:RFTDevGroup,项目名称:RFTBackend,代码行数:4,代码来源:ModelMapperConfig.java
示例4: modelMapper
import org.modelmapper.Converter; //导入依赖的package包/类
@Bean
public ModelMapper modelMapper(List<Converter> converters) {
ModelMapper mapper = new ModelMapper();
converters.stream().forEach(mapper::addConverter);
return mapper;
}
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:9,代码来源:WebConfig.java
示例5: UserMapper
import org.modelmapper.Converter; //导入依赖的package包/类
public UserMapper() {
// Converters for complex field conversions
Converter<LocalDate, LocalDateTime> convertLocalDate2LocalDateTime = context -> context.getSource() == null ? null :
context.getSource().atStartOfDay();
Converter<LocalDateTime, LocalDate> convertLocalDateTime2LocalDate = context -> context.getSource() == null ? null :
context.getSource().toLocalDate();
// add PropertyMap<source,target> for unnatural field mappings
// map().set<Target>(source.get<Source>());
// map(source.get<Source>(), destination.get<Target>());
mapper.addMappings(new PropertyMap<User, UserDto>() {
@Override
protected void configure() {
map().setGivenName(source.getFirstname());
map().setFamilyName(source.getLastname());
using(convertLocalDate2LocalDateTime).map(source.getDob(), destination.getBday());
}
});
mapper.addMappings(new PropertyMap<UserDto, User>() {
@Override
protected void configure() {
map().setFirstname(source.getGivenName());
map().setLastname(source.getFamilyName());
using(convertLocalDateTime2LocalDate).map(source.getBday(), destination.getDob());
}
});
// add mapper.getTypeMap(<source>, <target>) pre/post conversion logic
}
开发者ID:roybailey,项目名称:research-graphql,代码行数:28,代码来源:UserMapper.java
示例6: ModelMapperAutoConfiguration
import org.modelmapper.Converter; //导入依赖的package包/类
public ModelMapperAutoConfiguration(ModelMapperProperties properties,
ObjectProvider<List<PropertyMap<?, ?>>> mappings,
ObjectProvider<List<Converter<?, ?>>> converters) {
this.properties = properties;
this.mappings = mappings.getIfAvailable();
this.converters = converters.getIfAvailable();
}
开发者ID:livelessons-spring,项目名称:building-microservices,代码行数:8,代码来源:ModelMapperAutoConfiguration.java
示例7: addConverters
import org.modelmapper.Converter; //导入依赖的package包/类
private void addConverters(ModelMapper modelMapper) {
if (this.properties.isAddConverters() && this.converters != null) {
for (Converter<?, ?> converter : this.converters) {
modelMapper.addConverter(converter);
}
}
}
开发者ID:livelessons-spring,项目名称:building-microservices,代码行数:8,代码来源:ModelMapperAutoConfiguration.java
示例8: converter
import org.modelmapper.Converter; //导入依赖的package包/类
public abstract Converter<S, D> converter();
开发者ID:rozidan,项目名称:modelmapper-spring-boot-starter,代码行数:2,代码来源:ConverterConfigurer.java
注:本文中的org.modelmapper.Converter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论