2017-06-01 57 views
0

我有以下映射:映射不施加成亞類

@Mapper 
public interface ParticulierMapper { 

ParticulierMapper INSTANCE = Mappers.getMapper(ParticulierMapper.class); 
TParticulier toDTO(Particulier particulier); 
Particulier toEntity(TParticulier particulier); 
TParticulierAttributMeta toDTO(ParticulierAttributMeta particulierAttributMeta); 
ParticulierAttributMeta toEntity(TParticulierAttributMeta particulierAttributMeta); 
TAdresse toDTO(Adresse adresse); 
Adresse toEntity(TAdresse adresse); 

default String toEntity(TGufidValue value){ 
    return value.getGufid(); 
} 
default TGufidValue toDTO(String value){ 
    TGufidValue tGufidValue=new TGufidValue(); 
    tGufidValue.setGufid(value); 
    return tGufidValue; 
} 
default LocalDateTime map(XMLGregorianCalendar value){ 
    return value.toGregorianCalendar().toZonedDateTime().toLocalDateTime(); 
} 
}` 

的TGufidValue被正確地轉換成TParticulier/Particulier但被跳過到住址/ TAdresse轉換如下所示:

public Adresse toEntity(TAdresse adresse) { 

    if (adresse == null) { 

     return null; 
    } 

    Adresse adresse1 = new Adresse(); 

    adresse1.setLibelleAdresse(adresse.getLibelleAdresse()); 

    adresse1.setParticulierAttributMetas(tParticulierAttributMetaListToParticulierAttributMetaList(adresse.getParticulierAttributMetas())); 

    adresse1.setBoite(adresse.getBoite()); 

    adresse1.setComplement(adresse.getComplement()); 

    adresse1.setLocalisationSpatiale(adresse.getLocalisationSpatiale()); 

    adresse1.setLocalite(adresse.getLocalite()); 

    adresse1.setNumero(adresse.getNumero()); 

    adresse1.setRegion(adresse.getRegion()); 

    adresse1.setVille(adresse.getVille()); 

    adresse1.setVoie(adresse.getVoie()); 

    return adresse1; 
} 

所有跳過TGufidValue對象的TAddress字段,因此不會出現在TAdresse轉換中。 在TParticulier/Particulier之外的其他課程中,是否有特殊的做法可以在全球範圍內提供此類轉換?

回答

0

沒關係我發現我的問題。只是在使用TGufidValue時,dto和實體字段沒有相同的名稱。編譯時警告可能很有意思,表明存在一些不匹配的字段。

+0

如果目標bean中的一個屬性,在你的案例'Adresse'尚未被映射,你應該得到一個警告。您甚至可能無法構建,即報告錯誤。查看[Mapper#unmappedTargetPolicy](http://mapstruct.org/documentation/stable/api/org/mapstruct/Mapper.html#unmappedTargetPolicy--)。如果確實沒有警告,請打開問題 – Filip