【问题标题】:MapStruct 1.3.0.Beta2 passing DTO to qualifiedByName methodMapStruct 1.3.0.Beta2 将 DTO 传递给qualifiedByName 方法
【发布时间】:2020-12-21 09:17:27
【问题描述】:

我正在使用MapStruct 1.3.0 Beta2,我想通过DTO 我在qualifiedByName 方法中进行映射,例如:

@Mapper(componentModel = "spring")
public interface UserMapper {

  @Mapping(target = "id", qualifiedByName = "test")
  UserDTO entityToUser(User entity);

  @Named("test")
  default Integer test(UserDTO userDto) {
    return userDto.getId();
  }
}

显然我必须做更复杂的操作,这只是一个例子。有没有办法做到这一点??

谢谢

【问题讨论】:

  • 还有 1.3.0.Final 和 1.4.0.CR1(1.4.0.Final 正在制作中)

标签: spring-boot mapping dto mapstruct


【解决方案1】:

我已解决如下:

@Mapper(componentModel = "spring")
public interface UserMapper {

  UserDTO entityToUser(User entity);

  @AfterMapping
  default void test(User entity, @MappingTarget UserDTO userDto) {
      // some operations
  }
}

希望有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-25
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 2015-11-04
    • 2011-01-01
    • 2021-04-25
    相关资源
    最近更新 更多