有 Enum 类型
MapStruct 可以非常轻松的将 Bean 对象映射到 DTO 对象中用于传输。
MapStruct会在编译阶段实现其接口。
要是 Bean 中有 Enum 类型,需要去对应 DTO 中的String ,需要注意以下几点:
Bean 中重写 setType(String type) 方法
DTO 中重写 setType(CarType carType) 方法
1.Bean
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Car {
private String make;
private int numberOfSeats;
private CarType type;
public void setType(String type) {
this.type = CarType.convert(type);
}
}
2.Dto
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CarDto {
private String make;
private int seatCount;
private String type;
private String description;
public void setType(CarType carType) {
this.type = car