2017-12-05 12 views
0

안녕하세요. 이제는 간단한 클래스 간의 매핑을 수행 할 수 있습니다. 이제 인터페이스간에 매핑해야합니다. 많은 클래스가 이러한 인터페이스를 구현하는 2 개의 인터페이스가 있습니다. 이후 어떻게해야할지 알지 못했기 때문에 인터페이스 A의 특정 유형에 매핑되었습니다. 역방향 매핑이 필요합니다. 속성은 하위 클래스에있을 수 있으며이 경우 역 매핑을 수행하는 방법입니다. @inheritinverseconfiguratioin 태그가 작동하지 않았다. 난의 두 가지 인터페이스mapStruct의 인터페이스 간 매핑

public interface DomainInterface { } 
public interface DtoInterface { } 

및 구현

public class Domain1Impl implements DomainInterface { } 
public class Domain2Impl implements DomainInterface { } 
public class Dto1Impl implements DtoInterface { } 
public class Dto2Impl implements DtoInterface { } 

매퍼 예제가 있다고 가정 해 봅시다

+2

relevan을 추가해야합니다. 프로젝트의 코드 – anyanwu

답변

0

을 이해하는 대답에 약간의 코드를 얻는 경우에 대신 읽기 설명의
는, 정말 도움이 될 것입니다

@Mapper 
public interface MyInterfaceMapper { 

    default DtoInterface map(DomainInterface domain) { 
     if (domain instanceof Domain1Impl) { 
      return mapDomain1((Domain1Impl)state); 
     } 
     else if (domain instanceof Domain2Impl) { 
      return mapDomain2((Domain2Impl)state); 
     } 

    } 

    Dto1Impl mapDomain1(Domain1Impl domain); 

    Dto2Impl mapDomain2(Domain2Impl domain); 

}