我有两个类似这样的域类。
@Getter
@Setter
public class User {
private String name;
}
@Getter
@Setter
public class Student extends User {
private int grade;
}
我还有两个类似这样的Dto类。
@Getter
@SuperBuilder
public class UserDto {
private final String name;
}
@Getter
@SuperBuilder
public class StudentDto extends UserDto {
private final int grade;
}
因此,我创建了一个映射器类StudentMapper,它继承了GenericMapper。
public interface GenericMapper<D, E> {
D toDto(E e);
E toEntity(D d);
}
@Mapper(componentModel = "spring")
public interface StudentMapper extends GenericMapper<StudentDto, Student> {
}
但是在编译Mapper时我遇到了一个错误。
"StudentDto没有可访问的构造函数。"
这些代码有什么问题吗?
我希望StudentDto是不可修改的。 使用lombok和mapstruct实现最佳方法是什么?
您可以从这里获取源代码。 https://github.com/jangdaewon/sandbox.lombokmapstruct
<annotationProcessorPaths>
的顺序,使得Lombok成为最后一个条目? - Jan Rieke<annotationProcessorPaths>
的顺序后,错误消息已消失。谢谢。 - Shinbop