添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
安静的火腿肠  ·  Cannot read ...·  7 月前    · 
重情义的香槟  ·  How to make async ...·  8 月前    · 
奔放的打火机  ·  人工角膜_百度百科·  1 年前    · 

mapstruct 忽略某些字段

MapStruct 是一个 Java 库,可以用于自动生成 POJO(Plain Old Java Object,简单的 Java 对象)之间的映射代码。如果您想要忽略某些字段,可以使用 @Mapping(ignore = true) 注解来指定。例如:

@Mapper
public interface UserMapper {
    @Mapping(target = "id", ignore = true)
    UserDTO toDTO(User user);

在上面的示例中,输出的 UserDTO 对象的 id 字段将被忽略。

如果您想要忽略多个字段,可以使用 @Mappings 注解,并指定多个 @Mapping 注解,例如:

@Mapper
public interface UserMapper {
    @Mappings({
        @Mapping(target = "id", ignore = true),
        @Mapping(target = "password", ignore = true)
    UserDTO toDTO(User user);

在上面的示例中,输出的 UserDTO 对象的 id 和 password 字段将被忽略。

  •