- интерфейс Mapper: < /strong> < /p>
Код: Выделить всё
@Mapper( componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE, unmappedSourcePolicy = ReportingPolicy.IGNORE ) public interface UserTaskMapper { UserTask toEntity(UserTaskRequest userTaskRequest); UserTaskResponse toResponse(UserTask userTask); } - class: [/b]
Код: Выделить всё
@Entity @Getter @Setter @RequiredArgsConstructor @Table(name = "user_tasks") public class UserTask { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @ManyToOne @JoinColumn(name = "user_id", nullable = false) private User user; @ManyToOne @JoinColumn(name = "task_id", nullable = false) private Task task; private Boolean isCompleted; private String projectUrl; private LocalDateTime submittedAt; } - запрос DTO:
Код: Выделить всё
@Getter @Setter public class UserTaskRequest { private Long taskId; private Set userIds; private Boolean isCompleted = false; private String projectUrl; } - ответ dto:
Код: Выделить всё
@Getter @Setter public class UserTaskResponse { private Long id; private Long userId; private TaskResponse task; private Boolean isCompleted; private String projectUrl; private LocalDateTime submittedAt; } - сгенерированная реализация Mapper:
Код: Выделить всё
@Generated( value = "org.mapstruct.ap.MappingProcessor", date = "2025-05-03T19:59:56+0400", comments = "version: 1.6.3, compiler: IncrementalProcessingEnvironment from gradle-language-java-8.13.jar, environment: Java 17.0.14 (Amazon.com Inc.)" ) @Component public class UserTaskMapperImpl implements UserTaskMapper { @Override public UserTask toEntity(UserTaskRequest userTaskRequest) { if (userTaskRequest == null) { return null; } UserTask userTask = new UserTask(); return userTask; } @Override public UserTaskResponse toResponse(UserTask userTask) { if (userTask == null) { return null; } UserTaskResponse userTaskResponse = new UserTaskResponse(); return userTaskResponse; } }
Код: Выделить всё
implementation 'org.mapstruct:mapstruct:1.6.3'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.3'
< /ol>
Несмотря на эти усилия, картирование все еще не работает правильно. Как это исправить?
Подробнее здесь: https://stackoverflow.com/questions/796 ... pping-code