MapstructqualifiedByName多参数

问题描述 投票:0回答:1

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

我需要使用参数将对象列表重载到对象。

java spring spring-boot mapstruct mapper
1个回答
0
投票

Maper

@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;
}
© www.soinside.com 2019 - 2024. All rights reserved.