我有一个实体,其属性我曾经这样写 私有(private)龙重症监护室;
我正在使用映射结构:
这是我针对所述实体的映射器:
@Mapper(componentModel = "spring")
public interface ProtectionQueryMapper extends EntityMapper<ProtectionQueryDto, Protection> {
ProtectionQueryDto toDto(Protection protection);
Protection toEntity(ProtectionQueryDto protectionQueryDto);
List<Protection> toEntity(List<ProtectionQueryDto> protectionQueryDtos);
List<ProtectionQueryDto> toDto(List<Protection> protections);
}
public interface EntityMapper<D, E> {
E toEntity(D dto);
D toDto(E entity);
List<E> toEntity(List<D> dtoList);
List<D> toDto(List<E> entityList);
}
我遇到的问题是我想从 ICU go icu 更改属性,我这样做了,并导致了此错误:
nested exception is java.lang.NoSuchMethodError:
Protection.getICU()Ljava/lang/Long;
mapstruct 似乎基于以下内容生成其 getter 和 setter:
私有(private)长重症监护室;
生成方法如 setICU 和 getICU。
但现在我已将属性从 ICU 更改为 icu mapstruct 并没有将其方法更新为 setIcu
和 getIcu
。
我无法手动更改 mapstruct
生成的文件。
这也是我的pom.xml(至少是关于mapstruct的部分)
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.3.0.Final</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
<arg>-Amapstruct.defaultComponentModel=spring</arg>
</compilerArg>
</compilerArgs>
</configuration>
</plugin>
知道如何让mapstruct更新其生成的源文件吗?
最佳答案
您需要首先按顺序提供lombok插件,然后是mapstruct-processor插件,就像这样。
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
关于java - Mapstruct 未在生成的源文件中更新其 getter 和 setter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56849053/