Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MapStruct:我如何过滤到我想要的字段,并且不';我不想做地图?_Java_Mapping_Entity_Dto_Mapstruct - Fatal编程技术网

Java MapStruct:我如何过滤到我想要的字段,并且不';我不想做地图?

Java MapStruct:我如何过滤到我想要的字段,并且不';我不想做地图?,java,mapping,entity,dto,mapstruct,Java,Mapping,Entity,Dto,Mapstruct,我有一个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 S

我有一个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;

}
我不想映射id、用户名、密码和电子邮件。我怎样才能指出这些字段没有被卡住

User user = fromUserDTO(userDTO);
我找到了答案

  • 我可以忽略一个字段:
  • 或者我可以忽略等于null的字段:
  • User user = fromUserDTO(userDTO);
    
    @Mapping(target = "id", ignore = true)
    User fromUserDTO(UserDTO userDTO);
    
    @Mapping(target="id", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
    User fromUserDTO(UserDTO userDTO);