gpt4 book ai didi

java - Mapstruct-找不到没有源的属性的映射

转载 作者:行者123 更新时间:2023-12-01 19:47:01 29 4
gpt4 key购买 nike

使用MapStruct最新版本1.3.0最终版..

@Mapping(target = "identifier", qualifiedBy = PensionOfferApplicationFilter.Identifier.class)
@Mapping(target = "optionNumber", source = "insurancePeriod", qualifiedBy = PensionOfferApplicationFilter.OptionNumber.class)
@Mapping(target = "creationDate", qualifiedBy = PensionOfferApplicationFilter.CreationDate.class)
@Mapping(target = "editedPieces", source = "insurancePeriod", qualifiedBy = PensionOfferApplicationFilter.EditedPieces.class)


对于“标识符”和“ creationDate” ..我在自动生成的Impl文件中找不到任何映射。.这就是我所看到的..如何在没有源的情况下传递某些东西?

    if (insurancePeriod == null) {
return null;
} else {
PensionApplication pensionApplication = new PensionApplication();
pensionApplication.setEditedPieces(this.pensionOfferApplicationFilter.editedPieces(insurancePeriod, request, resultDto));
pensionApplication.setPensionCase(this.insurancePeriodPensionHandlerPartyPensionCase(insurancePeriod));
pensionApplication.setOptionNumber(this.pensionOfferApplicationFilter.optionNumber(insurancePeriod));
pensionApplication.setPensionHandlerParty(insurancePeriod.getPensionHandlerParty());
pensionApplication.setType("elaketarjous");
return pensionApplication;


标识符应映射到PensionOfferApplicationFilter类中定义的此方法

@Identifier
public String identifier() {
return String.valueOf(pensionApplicationRepository.getPensionApplicationIdentifier());
}

最佳答案

public interface MyMapper{

@Mapping(target = "identifier", ignore = true ) /* leave it to aftermapping */
@Mapping(target = "optionNumber", source = "insurancePeriod", qualifiedBy = PensionOfferApplicationFilter.OptionNumber.class)
@Mapping(target = "creationDate", qualifiedBy = PensionOfferApplicationFilter.CreationDate.class)
@Mapping(target = "editedPieces", source = "insurancePeriod", qualifiedBy = PensionOfferApplicationFilter.EditedPieces.class)
Target map( Source source, @Context PensionApplicationRepository repo /* pass the repo as context */);

@AfterMapping
default map( Source source, @AfterMapping Target target, @Context PensionApplicationRepository repo ) {
target.setIdentifier( String.valueOf(repo.getPensionApplicationIdentifier() );
}

}


附带说明:您真的需要所有预选赛吗?这些仅是处理冲突所必需的:当多个组合具有相同的源类型,目标类型时

关于java - Mapstruct-找不到没有源的属性的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59115357/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com