感谢!!!我用qualifiedByName实现了
@Mapping(target = "hobbyList", source = "personDTO", qualifiedByName = "toHobbyList")
Person toPerson(PersonDTO personDTO);
@Named("toHobbyList")
default List<Hobby> toHobbyList(PersonDTO personDTO) {
List<Hobby> list = new ArrayList<>();
if (StringUtils.isNotEmpty(personDTO.getHobbyName1()) || StringUtils.isNotEmpty(personDTO.getDuration1())) {
list.add(new Hobby(personDTO.getHobbyName1(), personDTO.getDuration1()));
}
if (StringUtils.isNotEmpty(personDTO.getHobbyName2()) || StringUtils.isNotEmpty(personDTO.getDuration2())) {
list.add(new Hobby(personDTO.getHobbyName2(), personDTO.getDuration2()));
}
return list;
}
@eason1314: great!