MapStruct

编程入门 行业动态 更新时间:2024-10-14 18:13:11

<a href=https://www.elefans.com/category/jswz/34/1749068.html style=MapStruct"/>

MapStruct

lombok 和 mapstruct 配合转换 bean 后,mapstruct 生成空的实现(对象是有的,但是属性没赋值)

解决思路

在 maven-compiler-plugin 插件下多配置一个 lombok-mapstruct-binding 注解处理器来绑定mapstruct 和 lombok

代码实现

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>8</source><target>8</target><encoding>UTF-8</encoding><annotationProcessorPaths><!-- 必须要加, 否则生成不了 MapperImpl 实现类 --><path><groupId>org.mapstruct</groupId><artifactId>mapstruct-processor</artifactId><version>1.4.0.Final</version></path><path><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.20</version></path><!-- 如果是 0.1.0 有可能出现生成了maptruct的实现类, 但该类只创建了对象, 没有进行赋值 --><path> <groupId>org.projectlombok</groupId><artifactId>lombok-mapstruct-binding</artifactId><version>0.2.0</version></path></annotationProcessorPaths></configuration>
</plugin>

更多推荐

MapStruct

本文发布于:2024-02-12 19:15:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1689047.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MapStruct

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!