I have a DTO. I want to map not all field in MapStruct.
For example, User and UserDTO
public class UserDTO {
private Long id;
private String username;
private String password;
private String email;
private boolean active;
private String activationCode;
private Set<Role> roles;
}
I have next mapper:
User fromUserDTO(UserDTO userDTO);
I don't want to map id, username, password, email. How can I point out that these fields don't get stuck?
User user = fromUserDTO(userDTO);
I've found the answer.
@Mapping(target = "id", ignore = true)
User fromUserDTO(UserDTO userDTO);
@Mapping(target="id", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
User fromUserDTO(UserDTO userDTO);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.