本文介绍: SpringBoot集成MapStruct

引入mapstruct依赖

<dependency>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct</artifactId>
    <version>${org.mapstruct.version}</version>
</dependency>

配置maven-compiler-plugin

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <encoding>UTF-8</encoding>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${org.mapstruct.version}</version>
                    </path>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${lombok.version}</version>
                    </path>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok-mapstruct-binding</artifactId>
                        <version>${mapstruct-binding.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

附:版本

<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>

<lombok.version>1.18.22</lombok.version>

<mapstruct-binding.version>0.2.0</mapstruct-binding.version>

代码示例

@Mapper
public interface NodeMessageConverter {

    /**
     * 转换实例
     */
    NodeMessageConverter INSTANCE = Mappers.getMapper(NodeMessageConverter.class);

    /**
     * 审批消息转换
     */
    ApprovalMessageEntity convertApprovalMessage(NodeMessageParam messageParam);

    /**
     * 采购消息转换
     */
    PurchaseMessageEntity convertPurchaseMessage(NodeMessageParam messageParam);
}


// 应用
PurchaseMessageEntity purchaseMessageEntity = NodeMessageConverter.INSTANCE.convertPurchaseMessage(messageParam);

原文地址:https://blog.csdn.net/whg18526080015/article/details/134601738

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_51027.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注