我有一个这样的模型:
public class PersonDto {
private CarDto car;
public CarDto getCar() {
return car;
}
public void setCar(CarDto car) {
this.car = car;
}
public static class CarDto {
private String model;
private String color;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
}
VO 是不可变的:
public class PersonVo {
private final CarDto car;
public PersonVo(CarDto car) {
super();
this.car = car;
}
public CarDto getCar() {
return car;
}
public static class CarDto {
private final String model;
private final String color;
public CarDto(String model, String color) {
super();
this.model = model;
this.color = color;
}
public String getModel() {
return model;
}
public String getColor() {
return color;
}
}
}
有没有一种简单的方法可以使用ModelMapper
Providers 将此场景从 Dto 转换为 Vo?
我无法使用一个提供程序来解决它,PersonVo
因为当我创建新对象时,我不知道如何解析CarDto
...
public class PersonVoProvider implements Provider<PersonVo> {
public PersonVo get(org.modelmapper.Provider.ProvisionRequest<PersonVo> request) {
PersonDto source = PersonDto.class.cast(request.getSource());
return new PersonVo(car); ????????????
}
}