spring – 使用MapStruct将实体映射到DTO

weixin_38071069 2019-09-12 10:27:28
我是maptruct中的新手,我使用spring作为DI我跟进了关于DI容器的MapStruct文档页面4.2我尝试将我的实体映射到dto,如下所示: @Mapper(componentModel = "spring") public interface CustomerMapper { @Mapping(source = "registered",target = "activeProfile") CustomerDto customerToCustomerDto(Customer customer); } 当我运行mvn install时出现此错误: java:27: error: No property named "registered" exists in source parameter(s). @Mapping(source = "registered",target = "activeProfile") 我的实体使用lombok,我相信有注册的字段 请帮忙
...全文
318 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38073873 2019-09-12
  • 打赏
  • 举报
回复
您不必删除Lombok.您可以将其设置为在MapStruct之前工作,如ahus1所述https://github.com/mapstruct/mapstruct/issues/510 <!-- first de-lombok the sources to make getters/setters visible for mapstruct, but *DON'T'* add the output directory to the sources, as we will only need it for mapstruct processing --> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>${org.projectlombok.maven.version}</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> <configuration> <sourceDirectory>src/main/java</sourceDirectory> <addOutputDirectory>false</addOutputDirectory> <outputDirectory>${project.build.directory}/delombok</outputDirectory> </configuration> </execution> </executions> </plugin> <!-- use the de-lomobok files to create the necessary mappers --> <plugin> <groupId>org.bsc.maven</groupId> <artifactId>maven-processor-plugin</artifactId> <version>2.2.4</version> <configuration> <defaultOutputDirectory> ${project.build.directory}/generated-sources/mapstruct </defaultOutputDirectory> <processors> <processor>org.mapstruct.ap.MappingProcessor</processor> </processors> <sourceDirectory> ${project.build.directory}/delombok </sourceDirectory> </configuration> <executions> <execution> <id>process</id> <phase>generate-sources</phase> <goals> <goal>process</goal> </goals> </execution> </executions> </plugin> <!-- now take the original sources together with the created mappers to the compiler --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <annotationProcessors> <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor> </annotationProcessors> </configuration> </plugin>

435

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧