java - Mapstruct 未在生成的源文件中更新其 getter 和 setter

标签 java spring lombok mapstruct

我有一个实体,其属性我曾经这样写 私有(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 并没有将其方法更新为 setIcugetIcu

我无法手动更改 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插件,然后是ma​​pstruct-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/

相关文章:

java - Bean创建异常: Injection of autowired dependencies failed

java - Spring Boot 中的 SSL 证书

spring - SLF4J : Failed toString() invocation on an object of type lombok

gradle - 找不到参数的方法 annotationProcessor()

java - java中LinkedHashMap中的addEntry方法

java - 我可以区分 org.apache.commons.cli 中的短选项和长选项吗

java - 在 cucumber-jvm 测试中回滚事务

java - Lombok的@NonNull的使用说明

java - 如何在 python 中将字节数组转换为 double ?

java - 在已经扩展 ActionBarActivity 的主 Activity 中扩展一个附加类?