嗨,我正在尝试将我的源映射到目标,但我收到了这个错误。
这是我的 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”吗?
通常属性的访问器是使用第一个字符属性名称大写生成的,因此
rDAccount
从 MapStruct
(我想也从 Lombok)解释为 RDAccount
.rDAccount
重命名为 RDAccount
一切都应该没问题。