给出以下将FarmInputDto
映射到Farm
的方法:
@Mapping(target = "assignment", source = "user", qualifiedByName = "addUserToAssignments")
public abstract Farm toFarm(FarmInputDto input, User user);
是否可以在自定义映射器方法中访问刚创建的Farm
实例?
protected UserFarmAssignment addUserToAssignments(User user) {
return new UserFarmAssignment(user, "$FARM_INSTANCE?");
}
我已经读过@MappingTarget,但这是行不通的(也许无论如何在这种情况下都不能这样使用):
protected List<UserFarmAssignment> addUserToAssignments(User user, @MappingTarget Farm farm) { }