我尝试配置orika mapper。我有5个实体和5个dto。我的配置是正确的,但是我找不到关于如何为不同类配置Map器的任何信息。那么,是可以为某些类创建一个配置,还是应该为每对类创建一个配置呢?
@Configuration
public class MapperConfig implements OrikaMapperFactoryConfigurer {
@Bean
DatatypeFactory datatypeFactory() throws DatatypeConfigurationException {
return DatatypeFactory.newInstance();
}
@Bean
DefaultMapperFactory.MapperFactoryBuilder<?, ?> orikaMapperFactoryBuilder() {
DefaultMapperFactory.Builder orikaMapperFactoryBuilder = new DefaultMapperFactory.Builder();
return orikaMapperFactoryBuilder;
}
@Bean
public MapperFactory orikaMapperFactory(DefaultMapperFactory.MapperFactoryBuilder<?, ?> orikaMapperFactoryBuilder) {
MapperFactory orikaMapperFactory = orikaMapperFactoryBuilder.build();
this.configure(orikaMapperFactory);
return orikaMapperFactory;
}
public void configure(MapperFactory orikaMapperFactory) {
orikaMapperFactory.classMap(Author.class, AuthorDto.class)
.byDefault()
.register();
}
@Bean
public MapperFacade orikaMapperFacade(MapperFactory orikaMapperFactory) {
MapperFacade orikaMapperFacade = orikaMapperFactory.getMapperFacade();
return orikaMapperFacade;
}
}
1条答案
按热度按时间fsi0uk1n1#
可以,您需要在configure方法中为其他两对类注册Map器
例子: