MapStructPlus

MapStructPlus 是 MapStruct 的增强工具,自动生成 Mapper 接口并强化功能,使 Java 类型转换更加便捷优雅。完全兼容 MapStruct,支持 Maven、Gradle 等构建工具。

Check out MapStructPlus on CurateClick

• Copy the embed code to showcase this product on your website

• Share on X to spread the word about this amazing tool

  • 官网 | 国内镜像网站- 项目地址Mapstruct Plus 是 Mapstruct 的增强工具,在 Mapstruct 的基础上,实现了自动生成 Mapper 接口的功能,并强化了部分功能,使 Java 类型转换更加便捷、优雅。和 Mapstruct 一样,本质上都是一个基于 JSR 269 的 Java 注释处理器,因此可以由 Maven 、Gradle 、Ant 等来构建触发。Mapstruct Plus 内嵌 Mapstruct ,和 Mapstruct 完全兼容,如果之前已经使用 Mapstruct ,可以无缝替换依赖。简单示例假设有两个类 UserDto 和 User ,分别表示数据层对象和业务层对象:- UserDtojavapublic class UserDto { private String username; private int age; private boolean young; // getter 、setter 、toString 、equals 、hashCode}- Userjavapublic class User { private String username; private int age; private boolean young; // getter 、setter 、toString 、equals 、hashCode}添加依赖: 引入 mapstruct-plus-spring-boot-starter 依赖:xml<properties> <mapstruct-plus.version>1.3.6</mapstruct-plus.version></properties><dependencies> <dependency> <groupId>io.github.linpeilie</groupId> <artifactId>mapstruct-plus-spring-boot-starter</artifactId> <version>${mapstruct-plus.version}</version> </dependency></dependencies><build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <annotationProcessorPaths> <path> <groupId>io.github.linpeilie</groupId> <artifactId>mapstruct-plus-processor</artifactId> <version>${mapstruct-plus.version}</version> </path> </annotationProcessorPaths> </configuration> </plugin> </plugins></build>指定对象映射关系:在 User 或者 UserDto 上面增加注解 —— @AutoMapper,并设置 targetType 为对方类。例如:java@AutoMapper(target = UserDto.class)public class User { // ...}测试:java@SpringBootTestpublic class QuickStartTest { @Autowired private Converter converter; @Test public void test() { User user = new User(); user.setUsername("jack"); user.setAge(23); user.setYoung(false); UserDto userDto = converter.convert(user, UserDto.class); System.out.println(userDto); // UserDto{username='jack', age=23, young=false} assert user.getUsername().equals(userDto.getUsername()); assert user.getAge() == userDto.getAge(); assert user.isYoung() == userDto.isYoung(); User newUser = converter.convert(userDto, User.class); System.out.println(newUser); // User{username='jack', age=23, young=false} assert user.getUsername().equals(newUser.getUsername()); assert user.getAge() == newUser.getAge(); assert user.isYoung() == newUser.isYoung(); }}小结:引入依赖后,使用 MapStructPlus 的步骤非常简单。- 给需要转换的类添加 AutoMapper 注解;- 获取 Converter 实例,调用 convert 方法即可。

Latest Weekly Picks

make.ink favicon
Weekly Pick

Your AI tattoo generator for pro-grade concepts

Leo Wade
sellfy.com favicon
Weekly Pick

A code-free online store builder to turn views into revenue. Sell digital products, subscriptions, and merch, without fees or hassle.

Maris
www.videotoblog.ai favicon
Weekly Pick

Convert videos into awesome blog posts.

Video To Blog
www.sellerpic.ai favicon
Weekly Pick

SellerPic is the all-in-one AI design platform for e-commerce

SellerPic
fastimage.ai favicon
Weekly Pick

Fast Image AI instantly transforms your photos into stunning styles like Ghibli, Sketch, and Pixar. Effortlessly control image elements and create amazing effects with just one click.

Fast AI Team
linkedinpro.daisy.so favicon
Weekly Pick

AI-powered tool that transforms casual photos into professional LinkedIn headshots instantly. No photographer needed—just upload and download.

Gabriel
crevas.ai favicon
Weekly Pick

Crevas unifies Veo 3, Sora 2, Nano Banana and more into one intuitive canvas — so filmmakers can script, prompt, and generate cinematic stories without switching tools or losing consistency.

Spark Alpha
fotominiatur.com favicon
Weekly Pick

AI Foto Edit - Text to Image & Image Edit

foto miniatur