Код: Выделить всё
@Data
public class IndividualDTO {
private String passportNumber;
private String phoneNumber;
private UserDTO user;
@Data
public static class UserDTO {
@NotBlank
@Email
private String email;
private String secretKey;
private String firstName;
private String lastName;
private AddressDTO address;
}
@Data
public static class AddressDTO {
private String address;
private String city;
private String state;
private String zipCode;
private CountryDTO country;
}
@Data
public static class CountryDTO{
private String name;
}
}
IndividualMapper
Код: Выделить всё
@Mapper(componentModel = "spring", uses = {UserMapper.class, AddressMapper.class, CountryMapper.class})
public interface IndividualMapper {
IndividualMapper INSTANCE = Mappers.getMapper(IndividualMapper.class);
Individual toEntity(IndividualDTO dto);
IndividualDTO toDto(Individual entity);
}
Код: Выделить всё
@Mapper(componentModel = "spring")
public interface AddressMapper {
Address toAddressEntity(IndividualDTO.AddressDTO addressDTO);
IndividualDTO.AddressDTO toAddressDto(Address address);
}
< /code>
countrymapper < /strong> < /p>
< /blockquote>
@Mapper(componentModel = "spring")
public interface CountryMapper {
Country toCountryEntity(IndividualDTO.CountryDTO countryDTO);
IndividualDTO.CountryDTO toCountryDto(Country country);
}
< /code>
usermapper < /strong> < /p>
< /blockquote>
@Mapper(componentModel = "spring")
public interface UserMapper {
User toUserEntity(IndividualDTO.UserDTO userDTO);
IndividualDTO.UserDTO toUserDto(User user);
}
Код: Выделить всё
@Component
public class IndividualMapperImpl implements IndividualMapper {
@Override
public Individual toEntity(IndividualDTO dto) {
if ( dto == null ) {
return null;
}
Individual individual = new Individual();
return individual;
}
@Override
public IndividualDTO toDto(Individual entity) {
if ( entity == null ) {
return null;
}
IndividualDTO individualDTO = new IndividualDTO();
return individualDTO;
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... pring-boot