赞
踩
//@NotNull父类原本需要导入import javax.validation.constraints.NotNull;却导入了import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.NotNull;//错误的包
import lombok.Data;
@Data
public class QualityTestingStandardEntity{
@NotNull
private Integer baseScore;
}
导致子类使用@Data主键报错:Lombok needs a default constructor in the base class
import lombok.Data;
@Data//因为父类导错包,此时子类会报:Lombok needs a default constructor in the base class
public class QualityTestingStandardEntityDto extends QualityTestingStandardEntity{
}
父类
import lombok.Data;
import javax.validation.constraints.NotNull;//正确的包
@Data
public class QualityTestingStandardEntity{
@NotNull
private Integer baseScore;
}
子类使用@Data会提示需要使用@EqualsAndHashCode(callSuper=false)
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper=false)
public class QualityTestingStandardEntityDto extends QualityTestingStandardEntity{
}
lombok官方建议maven配置和spring boot推荐配置
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.24</version> <scope>provided</scope> </dependency> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <!--打包时排除lombok依赖,因为lombok只在编译阶段使用--> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build>
lombok官方建议gradle配置
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。