Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
问题描述
这里是引用
在项目中同时使用 lombok 与mapstruct 包的时候,写了一个mapper,Log与LogDTO里面用了@Getter、@Setter注解
在运行的时候报错 Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface LogMapper { @Mappings({ @Mapping(source = "id", target = "idDTO"), @Mapping(source = "realName", target = "realNameDTO"), @Mapping(source = "name", target = "nameDTO"), }) LogDTO convertToDTO(Log log); @Mappings({ @Mapping(source = "idDTO", target = "id"), @Mapping(source = "realNameDTO", target = "realName"), @Mapping(source = "nameDTO", target = "name"), @Mapping(target = "address", constant = "无地址"), }) Log covertToDO(LogDTO logDTO); }
问题处理
查询了一些资料,有以下几种解决办法,针对我这个情况,是 采用了第三种解决办法,最有效的是下这种
(1)在pom文件中 加入binding 插件
pom.xml -> build-> plugins 下加入 lombok-mapstruct-binding
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> <annotationProcessorPaths> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>1.3.1.Final</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.14</version> <!--注意这里的版本号,建议不一样的,要改的和我一样,不然--> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> <version>0.2.0</version> <!--注意这里的版本号,不要更改,用阿里云镜像的,他里面只有这个版本的文件,不然依旧报错--> </path> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build>