【发布时间】:2021-04-25 14:05:35
【问题描述】:
如何使用 mapStruct 仅映射选定的字段并返回它们作为响应。
例如:
class Location {
String street;
String unit;
int postCode;
}
public class Car {
private Location location;.
}
public class CarDto {
private Location location;
}
现在我可以使用:
@Mapper
public interface CarMapper {
CarMapper INSTANCE = Mappers.getMapper( CarMapper.class );
CarDto returnObject = CarDto carToCarDto(Car car);
}
现在,returnObject 将包含具有street, unit and postCode 的位置。
但是,我只想用 returnObject.location 公开 street and postCode。
我怎样才能只公开那些选定的字段?
【问题讨论】: