Mapstruct 错误:源参数中不存在命名的属性

问题描述 投票:0回答:2

嗨,我正在尝试将我的源映射到目标,但我收到了这个错误。

这是我的 Pom.xml

<dependency>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct</artifactId>
    <version>1.5.5.Final</version>
</dependency>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.26</version>
</dependency>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok-mapstruct-binding</artifactId>
    <version>0.2.0</version>
</dependency>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <annotationProcessorPaths>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>1.5.5.Final</version>
            </path>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.26</version>
            </path>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-mapstruct-binding</artifactId>
                <version>0.2.0</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>

我的映射器:

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface CustomMapper {

    @Mapping(source = "rDAccount", target = "xfaceRDAccount")
    TargetClass mapToTarget(SourceClass sourceClass);
}

我的源类

import lombok.Data;

@Data
public class SourceClass {
    private String rDAccount;
}

我的目标类

import lombok.Data;

@Data
public class TargetClass {
    private String xfaceRDAccount;
}

运行 mvn clean install 后 我得到的错误:源参数中不存在名为“rDAccount”的属性。您指的是“RDAccount”吗?

java maven lombok mapstruct
2个回答
0
投票

通常属性的访问器是使用第一个字符属性名称大写生成的,因此

rDAccount
MapStruct
(我想也从 Lombok)解释为
RDAccount
.
只需将
rDAccount
重命名为
RDAccount
一切都应该没问题。


0
投票

在映射器调用而不是@Mapping(source = "rDAccount", target = "xfaceRDAccount") 尝试使用@Mapping(source = "RDAccount", target = "xfaceRDAccount")

lombok为rDAccount生成的getters和setters好像是getRDAccount和setRDAccount。

Generated getter and setter

© www.soinside.com 2019 - 2024. All rights reserved.