2017-07-18 235 views
0

我需要將xml轉換爲jpa實體。我使用jaxb來獲取我的DTO並使用mapStruct將dto轉換爲實體。 但是,我需要從數據中提取一些數據,並將其設置爲實體上的列表。我的mapper看起來像這樣如何在使用MapStruct的方法之間共享實例

Particulier toEntity(TParticulier particulier); 
List<AttributMeta> toEntity(List<TAttributMeta> attributMetas); 
default String extractMetaData(TAttributGufIdWithMeta value) { 
List<TAttributMeta> attributMetas=value.getAttributMeta(); 
???particulier.addAttributMetas(toEntity(attributMetas));?? 
return value.getValue().getGufid(); 
} 

我不知道如何訪問我的實體Particulier內的extractMetaData方法。

回答

0

爲了實現此類映射,您需要使用@MappingTarget結合@BeforeMapping/@AfterMapping。有關更多信息,請參閱參考文檔中的here

簡而言之,你需要你的映射器或用於引用有這樣一種方法:

@AfterMapping // It can also be @BeforeMapping 
public void afterMapping(TParticulier source, @MappingTarget Particulier target) { 
    //do what you need here 
} 
相關問題