Итак,
у нас есть класс Entity — Contact
Код: Выделить всё
public class Contact {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name",nullable = false)
private String name;
@Column(name = "email",nullable = false,unique = true)
private String email;
@Column(name = "phone",nullable = false)
private String phone;
}
Код: Выделить всё
public class ContactDto {
private Long id;
private String fname;
private String lname;
private String email;
private String phone;
}
I tried using MapStruct library. I am getting confused how to implement this logic. So kindly help me either with MapStruct or ModelMapper.
Код: Выделить всё
@Mapper
public interface ContactMapper {
ContactMapper INSTANCE = Mappers.getMapper(ContactMapper.class);
ContactDto mapToContactDto(Contact contact);
Contact mapToContact(ContactDto contactDto);
}
Источник: https://stackoverflow.com/questions/781 ... entity-and
Мобильная версия