gpt4 book ai didi

java - Mapstruct QualifiedByName 多参数

转载 作者:行者123 更新时间:2023-12-01 16:51:28 30 4
gpt4 key购买 nike

createMeaDto

mapper

mapperImpl

@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);

我需要将对象列表重载为带有参数的对象。

最佳答案

映射器

@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);
}

创建餐食

@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;
}

关于java - Mapstruct QualifiedByName 多参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61678955/

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