mapstruct、Java 和 Spring 未添加目标问题

mapstruct, Java and Spring Issues with target is not added

我确实有一个 DTO Class 和一个像这样的实体 Class。

class ADTO {
....
....
   HashSet<BDTO> b; 
}

class AEntity {
.....
......
   HashSet<BEntity> b; 
}

class BDTO {
...
....
    
}

class BEntity {
.....
......
   AEntity a; 
}

 

我尝试将映射器与 uses

一起使用
@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);

生成器class使用的是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);  
}