我有一个DTO。我不想映射MapStruct中的所有字段。
例如,User和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;
}
我有下一个映射器:
User fromUserDTO(UserDTO userDTO);
我不想映射ID,用户名,密码,电子邮件。如何指出这些字段不会卡住?
User user = fromUserDTO(userDTO);
答案 0 :(得分:1)
我找到了答案。
@Mapping(target = "id", ignore = true)
User fromUserDTO(UserDTO userDTO);
@Mapping(target="id", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
User fromUserDTO(UserDTO userDTO);