Files
ai4se-harness-suite/example-project/docs/standards/templates/03-ddd-assembler.md
ning-inspire 26975e5c3a Initial commit: ai4se-harness-suite
Import harness suite (skills, installers, overnight-runner, docs) as a fresh history for InspireChina.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-17 09:57:41 +08:00

1020 B
Raw Permalink Blame History

Assembler(Domain → DTO 转换)

package com.xxx.application.assembler;

import com.xxx.domain.aggregate.Xxx;
import lombok.Builder;
import lombok.Data;
import org.springframework.stereotype.Component;

@Component
public class XxxAssembler {

    public XxxResponse toResponse(Xxx xxx) {
        if (xxx == null) return null;
        return XxxResponse.builder()
                .id(xxx.getId())
                .userId(xxx.getUserId())
                .field1(xxx.getField1())
                .field2(xxx.getField2())
                .status(xxx.getStatus().name())
                .build();
    }

    @Data @Builder
    public static class XxxResponse {
        String id;
        String userId;
        String field1;
        String field2;
        String status;
    }
}

要点

  • Assembler 负责 Domain → DTO 的转换,在 Application 层
  • Converter(Infrastructure 层)负责 Domain ⟷ PO 的转换 — 见 08-ddd-converter.md
  • DTO 使用 @Data @Builder,内联为静态类