A helper project to access Mapstruct created mapper s with source and target types.
- Create model and dto objects.
public class Fruit {
}
public class FruitDto {
}
- Create a
Mapstruct
mapper which extendsGenericMapper
interface.
@Mapper( componentModel="spring" )
public interface FruitMapper extends GenericMapper<Fruit, FruitDto> {
}
- Inject
GenericMapperService
to your service and lookup for the mapper.
@Autowired
private GenericMapperService mapperService;
GenericMapper<Fruit, FruitDto> mapper = mapperService.getMapper( Fruit.class, FruitDto.class );
- You can also inject your
GenericMapper
to your services directly with Spring's injection capabilities.
@Autowired
GenericMapper<Fruit, FruitDto> fruitMapper;