我确实有一个DTO类和一个类似的实体类。
class ADTO {
....
....
HashSet<BDTO> b;
}
class AEntity {
.....
......
HashSet<BEntity> b;
}
class BDTO {
...
....
}
class BEntity {
.....
......
AEntity a;
}
我尝试使用使用的mapper
@Mapper(componentModel = "spring", uses=BMapper.class)
interface AMapper {
ADTO toDTO(AEntity a);
AEntity fromDTO(ADTO a);
}
@Mapper(componentModel = "spring", uses=AMapper.class)
interface BMapper {
BDTO toDTO(BEntity b);
BEntity fromDTO(ADTO a, BDTO b);
}
它是为";一对多";内部关系;JPA实体"DTO";正在用于JSON(Jackson解析器(。
ADTO toDTO(AEntity a);
生成器类正在使用上面的Bmapper方法。
但是
AEntity fromDTO(ADTO a);
没有使用Bmapper。如何强制使用Bmapper?
尝试使用@InheritInverseConfiguration
。它建议代码生成器将反向映射方法中的所有映射也应用到带注释的方法中。
@Mapper(componentModel = "spring", uses=BMapper.class)
interface AMapper {
ADTO toDTO(AEntity a);
@InheritInverseConfiguration
AEntity fromDTO(ADTO a);
}