Я поверил, что Code AI IntelliJ AI, что Mapstruct может сделать частичное обновление записи Java. Вводятся в заблуждение от AI? < /p>
Спасибо, что подумали о моем вопросе!public record Example(Long id, String name){}
public record ExampleWithBuilder(Long id, String name) {
public static ExampleWithBuilderBuilder builder() {
return new ExampleWithBuilderBuilder();
}
public static class ExampleWithBuilderBuilder {
private Long id;
private String name;
ExampleWithBuilderBuilder() {
}
public ExampleWithBuilderBuilder id(Long id) {
this.id = id;
return this;
}
public ExampleWithBuilderBuilder name(String name) {
this.name = name;
return this;
}
public ExampleWithBuilder build() {
return new ExampleWithBuilder(this.id, this.name);
}
public String toString() {
return "ExampleWithBuilder.ExampleWithBuilderBuilder(id=" + this.id + ", name=" + this.name + ")";
}
}
}
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface RacerMapper {
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
void partialUpdate(ExampleWithBuilder exampleWithBuilder, @MappingTarget Example example);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
ExampleWithBuilder partialUpdate(Example example, @MappingTarget ExampleWithBuilder exampleWithBuilder);
}
< /code>
Сгенерированный код показывает, что только возвращает MappingTarget < /p>
@Override
public Example partialUpdate(ExampleWithBuilder exampleWithBuilder, Example example) {
if ( exampleWithBuilder == null ) {
return example;
}
return example;
}
@Override
public ExampleWithBuilder partialUpdate(Example example, ExampleWithBuilder exampleWithBuilder) {
if ( example == null ) {
return exampleWithBuilder;
}
return exampleWithBuilder;
}
< /code>
pom.xml зависимость < /p>
org.mapstruct
mapstruct
1.6.3
Подробнее здесь: https://stackoverflow.com/questions/795 ... on-records