Java对象拷贝之MapStruct使用

gradle依赖

implementation group: 'org.mapstruct',name:'mapstruct-jdk8',version:'1.3.1.Final'
 annotationProcessor "org.mapstruct:mapstruct-processor:1.3.1.Final"

mapper(前提是原始对象与目标对象属性一致,不一致的需要单独处理)

@Mapper
public interface AbcMapper {

    AbcMapper INSTANCE = Mappers.getMapper(AbcMapper.class);

    List<Abc> bcdToAbc(List<Bcd> bcdList);
}

使用

List<Abc> abcList = AbcMapper.INSTANCE.bcdToAbc(bcdList);
  • 解决编译告警
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AbcMapper {

    AbcMapper INSTANCE = Mappers.getMapper(AbcMapper.class);

    List<Abc> bcdToAbc(List<Bcd> bcdList);
}

 

posted @ 2024-03-27 12:00  洞玄巅峰  阅读(40)  评论(0编辑  收藏  举报