是否可以使用 Orika 映射器为某些 类 创建一个配置?
Is it possible to create one configuration for some classes with Orika mapper?
我尝试配置 Orika 映射器。我有 5 个实体和 5 个 DTO。我的配置工作正常,但我找不到任何关于如何为不同 类 配置映射器的信息。那么是否可以为某些 类 创建一个配置,或者我应该为每一对 类 创建配置?
@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;
}
}
可以,你需要在configure方法[=11]中为另外两对类注册mapper =]
示例:
public void configure(MapperFactory orikaMapperFactory) {
orikaMapperFactory.classMap(Author.class, AuthorDto.class)
.byDefault()
.register();
orikaMapperFactory.classMap(A.class, B.class)
.byDefault()
.register();
}
我尝试配置 Orika 映射器。我有 5 个实体和 5 个 DTO。我的配置工作正常,但我找不到任何关于如何为不同 类 配置映射器的信息。那么是否可以为某些 类 创建一个配置,或者我应该为每一对 类 创建配置?
@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;
}
}
可以,你需要在configure方法[=11]中为另外两对类注册mapper =]
示例:
public void configure(MapperFactory orikaMapperFactory) {
orikaMapperFactory.classMap(Author.class, AuthorDto.class)
.byDefault()
.register();
orikaMapperFactory.classMap(A.class, B.class)
.byDefault()
.register();
}