87.6. mapping Extensions


Dozer 구성 요소는 Dozer 매핑 프레임워크에 대한 여러 확장을 사용자 지정 변환기로 구현합니다.  이러한 변환기는 Dozer 자체에서 직접 지원되지 않는 매핑 함수를 구현합니다.

87.6.1. 변수 매핑

변수 매핑을 사용하면 Dozer 구성 내의 변수 정의 값을 소스 필드의 값을 사용하는 대신 대상 필드에 매핑할 수 있습니다.  이는 다른 매핑 프레임워크의 상수 매핑과 동일합니다. 여기서 리터럴 값을 대상 필드에 할당할 수 있습니다.  변수 매핑을 사용하려면 매핑 구성 내에서 변수를 정의한 다음 VariableMapper 클래스에서 선택한 대상 필드에 매핑하기만 하면 됩니다.

<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd">
  <configuration>
    <variables>
      <variable name="CUST_ID">ACME-SALES</variable>
    </variables>
  </configuration>
  <mapping>
    <class-a>org.apache.camel.component.dozer.VariableMapper</class-a>
    <class-b>org.example.Order</class-b>
    <field custom-converter-id="_variableMapping" custom-converter-param="${CUST_ID}">
      <a>literal</a>
      <b>custId</b>
    </field>
  </mapping>
</mappings>
Copy to Clipboard Toggle word wrap

87.6.2. 사용자 정의 매핑

사용자 지정 매핑을 사용하면 소스 필드가 대상 필드에 매핑되는 방법에 대한 자체 논리를 정의할 수 있습니다.  Dozer 고객 변환기와 기능이 유사하며 두 가지 주요 차이점이 있습니다.

  • 사용자 지정 매핑을 사용하여 단일 클래스에 여러 변환기 메서드를 사용할 수 있습니다.
  • 사용자 지정 매핑을 사용하여 Dozer 관련 인터페이스를 구현할 필요가 없습니다.

사용자 지정 매핑은 매핑 구성에서 기본 제공 '_customMapping' 변환기를 사용하여 선언됩니다.  이 변환기의 매개변수에는 다음 구문이 있습니다.

[class-name][,method-name]
Copy to Clipboard Toggle word wrap

메서드 이름은 선택 사항입니다. Dozer 구성 요소는 매핑에 필요한 입력 및 출력 유형과 일치하는 메서드를 검색합니다.  사용자 정의 매핑 및 구성 예는 다음과 같습니다.

public class CustomMapper {
    // All customer ids must be wrapped in "[ ]"
    public Object mapCustomer(String customerId) {
        return "[" + customerId + "]";
    }
} 
Copy to Clipboard Toggle word wrap
<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd">
  <mapping>
    <class-a>org.example.A</class-a>
    <class-b>org.example.B</class-b>
    <field custom-converter-id="_customMapping"
        custom-converter-param="org.example.CustomMapper,mapCustomer">
      <a>header.customerNum</a>
      <b>custId</b>
    </field>
  </mapping>
</mappings>
Copy to Clipboard Toggle word wrap

87.6.3. 표현식 매핑

표현식 매핑을 사용하면 Camel의 강력한 언어 기능을 사용하여 표현식을 평가하고 매핑의 대상 필드에 결과를 할당할 수 있습니다.  Camel에서 지원하는 모든 언어는 표현식 매핑에 사용할 수 있습니다.  표현식의 기본 예제에는 Camel 메시지 헤더 또는 교환 속성을 대상 필드에 매핑하거나 여러 소스 필드를 대상 필드에 연결하는 기능이 포함되어 있습니다.  매핑 표현식의 구문은 다음과 같습니다.

[language]:[expression]
Copy to Clipboard Toggle word wrap

메시지 헤더를 대상 필드에 매핑하는 예:

<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd">
  <mapping>
    <class-a>org.apache.camel.component.dozer.ExpressionMapper</class-a>
    <class-b>org.example.B</class-b>
    <field custom-converter-id="_expressionMapping" custom-converter-param="simple:\${header.customerNumber}">
      <a>expression</a>
      <b>custId</b>
    </field>
  </mapping>
</mappings>
Copy to Clipboard Toggle word wrap

Dozer에서 EL을 사용하여 정의된 변수 값을 확인하려고 할 때 오류를 방지하려면 표현식 내의 모든 속성을 "\"로 이스케이프해야 합니다.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat