我需要在生成的mapper实现中注入一个spring服务类,以便我可以通过它来使用它
@Mapping(target="x", expression="java(myservice.findById(id))")"
Run Code Online (Sandbox Code Playgroud)
这适用于Mapstruct-1.0吗?
我正在使用mapstrcut将实体映射到dto,现在面临一个问题,在DTO中有一个额外的字段“折扣”,并且我需要mapstruct来管理填充此字段,并且该字段是根据2计算的值(salePrice和retailPrice)。
我的问题是如何像使用mapstruct一样进行这种映射。
@Mapping(target="discount", source="retailPrice-salePrice")
Run Code Online (Sandbox Code Playgroud)
当我尝试添加此行时,构建时的代码中断表示:
error: No property named "salePrice*retailPrice" exists in source parameter(s).
@Mapping(source="salePrice*retailPrice", target="discount")
Run Code Online (Sandbox Code Playgroud)
那么我该如何进行映射呢?