MapStruct未定义的方法调用



我有一个给定的场景,如下

class Curve {
private List<Point> points = new ArrayList<>();
public List<Point> getPoint() {
this.points;
}

public void addPoint(Point point) {
this.point.add(point);
}
}

映射程序类如下所示:

@Mapper
public interface CurveMapper {
CurveMapper INSTANCE = Mappers.getMapper(CurveMapper.class);
com.entity.Curve mapTo(com.dto.Curve);
}

MapStruct自动生成CurveMapperImpl类,如下所示:

public class CurveMapperImpl implements CurveMapper {

@Override
public com.entity.Curve mapTo(com.dto.Curve curve) {    
if (curve == null) {
return null;
}
com.entity.Curve curve1 = new com.entity.Curve();
for(com.dto.Point point : curve) {
curve1.add(convertPoint(point));
} 
}

mapStruct默认情况下查找curve.add()方法,但目标类具有curve.addPoint()。因此,它正在失败。

由于无法修改目标类结构,我如何要求mapStruct查找curve.addPoint()

try:

@Mapper( collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED )
public interface CurveMapper {
CurveMapper INSTANCE = Mappers.getMapper(CurveMapper.class);
com.entity.Curve mapTo(com.dto.Curve);
}

相关内容

  • 没有找到相关文章

最新更新