【发布时间】:2019-11-16 00:38:08
【问题描述】:
我正在尝试使用 Java 框架 Spring Boot 制作通用架构。
我尝试的映射器似乎没有像 .Net Core 框架中的 Automapper 这样的通用方法 -> Mapper.Map<TEntity>(source)。
有没有办法在不传递目标的情况下在 Spring Boot 中实现泛型映射?因为我的目标是
TEntity,无法直接实例化(T target = new T();)直接在方法(mapper.map(source, target))中传递。
在Service层的.Net Core框架中有一个我想用C#实现的例子。
public virtual TDataTransferObject Insert(TInsertDTO request){
var entity = Mapper.Map<TEntity>(request);
return Mapper.Map<TDataTransferObject>(Repository.Add(entity));
}
【问题讨论】:
-
喜欢this?
标签: java spring-boot dto