fat*_*ael 5 java mapping mapstruct
我收到 Mapstruct 异常,其中字段已存在于源和目标中:
@Mapper
public interface DccsMapper {
DccsMapper MAPPER = Mappers.getMapper( DccsMapper.class );
@Mappings({
@Mapping(source = "updatedDate", target = "updatedDate", dateFormat = "yyyy-MM-dd'T'HH:mm:ss"),
})
List<DataCenterCluster> entityListToDaoList(List<Dccs> source);
}
Run Code Online (Sandbox Code Playgroud)
来源:
public class Dccs {
@SerializedName("UpdatedDate")
@Expose
private String updatedDate;
Run Code Online (Sandbox Code Playgroud)
目的地:
public class DataCenterCluster {
@Column(name = "UPDATEDDATE")
private Date updatedDate;
Run Code Online (Sandbox Code Playgroud)
例外:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project Snow: Compilation failure
[ERROR] /C:......../DMapper.java:[18,17] No property named "updatedDate" exists in source parameter(s). Did you mean "empty"?
Run Code Online (Sandbox Code Playgroud)
Pom 还有:
<properties>
<org.mapstruct.version>1.3.1.Final</org.mapstruct.version>
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
</properties>
.
.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<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>1.18.10</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
天哪...我被困了最后一小时,当我发布问题时,答案浮现在我的脑海中。
对于基于列表的映射,我们需要添加以下内容:
List<DataCenterCluster> entityListToDaoList(List<Dccs> source);
@Mappings({
@Mapping(source = "updatedDate", target = "updatedDate", dateFormat = "yyyy-MM-dd'T'HH:mm:ss"),
})
DataCenterCluster entityToDao(Dccs source);
Run Code Online (Sandbox Code Playgroud)