Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?

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


    
        
            org.apache.maven.plugins
            maven-compiler-plugin
            3.5.1
            
                1.8
                1.8
                
                    
                        org.mapstruct
                        mapstruct-processor
                        1.3.1.Final
                    
                    
                        org.projectlombok
                        lombok
                        1.18.14
                        
                    
                    
                        org.projectlombok
                        lombok-mapstruct-binding
                        0.2.0
                        
                    
                
            
        
    

其他的就不介绍的了,我试了只有他最有效

你可能感兴趣的:(java,spring,mybatis)