[英]Spring-Boot MapStruct Generic implementation
public abstract class ServiceGenericImpl<E extends BaseEntity,T extends BaseDto>
implements ServiceGeneric<T> {
@Autowired
protected GenericRepository<E> genericRepository;
@Autowired
protected GenericMapper<E,T> genericMapper;
// code...
}
I try to generate Generic Implementation.我尝试生成通用实现。 Because many mapper such as city,person etc.
因为许多映射器,如城市、人等。
there is an error "Could not autowire. No beans of 'GenericMapper<E, T>' type found."出现错误“无法自动装配。找不到 'GenericMapper<E,T>' 类型的 bean。” How to generic implementation mapper and repository on service?
如何在服务上通用实现映射器和存储库?
public interface GenericMapper<E extends BaseEntity, T extends BaseDto> {
DTO toDTO(E entity);
E toEntity(T dto);
}
@Mapper(componentModel="spring")
public interface CityMapper extends GenericMapper<City, CityDto> {
}
Mapstruct needs some concrete classes eg X, XDto, so that it can analyse their properties and generate specific mapping code at compile time. Mapstruct 需要一些具体的类,例如 X、XDto,以便在编译时分析它们的属性并生成特定的映射代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.