Java 具有继承性的Mapstruct映射器
我有一个BaseEntity,它有一个名为Customer的子项 当我像这样制作mapper时:Java 具有继承性的Mapstruct映射器,java,spring,mapstruct,Java,Spring,Mapstruct,我有一个BaseEntity,它有一个名为Customer的子项 当我像这样制作mapper时: @Mapper(componentModel = "spring") public interface CustomerMapper { Customer toEntity(CustomerDTO model); List<Customer> toEntityList(List<CustomerDTO> models); CustomerDTO
@Mapper(componentModel = "spring")
public interface CustomerMapper {
Customer toEntity(CustomerDTO model);
List<Customer> toEntityList(List<CustomerDTO> models);
CustomerDTO toModel(Customer entity);
List<CustomerDTO> toModelList(List<Customer> entities);
}
客户:
@EqualsAndHashCode(callSuper = true)
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Data
publi class Customer extends BaseEntity {
private static final long serialVersionUID = 7054669140361044232L;
@Column(length = 50, unique = true, nullable = false)
private String login;
@Column(name = "password_hash", nullable = false, length = 60)
private String password;
}
我创建了一个示例来证明一切都按预期进行。请将此代码与您的代码进行比较,看看有什么不同。我创建了一个示例来演示一切都按预期工作。请将此代码与您的代码进行比较,看看有什么不同。这应该可以。你能在问题中添加“BaseEntity”、“Customer”和“CustomerTo”类的源代码吗?@Sudhir请检查我的更新
CustomerTo
是否有id
和uuid
字段?@MarcoLucidi是的,相同的类型和相同的名称这应该有效。你能在问题中添加“BaseEntity”、“Customer”和“CustomerDTO”类的源代码吗?@Sudhir请检查我的更新CustomerDTO
是否有id
和uuid
字段?@MarcoLucidi是的,相同的类型和相同的名称
@EqualsAndHashCode(callSuper = true)
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Data
publi class Customer extends BaseEntity {
private static final long serialVersionUID = 7054669140361044232L;
@Column(length = 50, unique = true, nullable = false)
private String login;
@Column(name = "password_hash", nullable = false, length = 60)
private String password;
}