[英]Mapstruct qualifiedByName multi parameters
@Named("createMealToEntity")
@Mapping(source = "restaurantId", target = "restaurantId")
@Mapping(ignore = true, target = "mealId")
Meal createMealToEntity(CreateMealDto createMealDto,String restaurantId);
@IterableMapping(qualifiedByName = "createMealToEntity")
List<Meal> createListMealToEntity(List<CreateMealDto> createMealDtoList, String restaurantId);
我需要使用参数将 object 的列表重载为 object。
映射器
@Mapper(componentModel = "spring")
public interface MealMapper {
@Named("createMealToEntity")
@Mapping(source = "restaurantId", target = "restaurantId")
@Mapping(ignore = true, target = "mealId")
Meal createMealToEntity(CreateMealDto createMealDto,String restaurantId);
@IterableMapping(qualifiedByName = "createMealToEntity")
List<Meal> createListMealToEntity(List<CreateMealDto> createMealDtoList, String restaurantId);
List<MealDto> entityToDto(List<Meal> mealList);
}
CreateMealDto
@Getter
@Setter
@NoArgsConstructor
public class CreateMealDto {
private String name;
private Double price;
private String imageUrl;
private String ingredients;
private Double timeToDo;
}
一顿饭
public class Meal {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(name = "meal_id")
private String mealId;
@Column(name = "name")
private String name;
@Column(name = "price")
private Double price;
@Column(name = "image_url")
private String imageUrl;
@Column(name = "ingredients")
private String ingredients;
@Column(name = "time_to_do")
private Double timeToDo;
@Column(name = "restaurant_id")
private String restaurantId;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.