mapstruct注解

2021-05-08  本文已影响0人  小诸葛686

常用注解

1.通过Mapping配置字段映射

  @Mapping(source = "name",target = "tname")

2.通过Mappings聚合配置多个Mapping

@Mappings({
            @Mapping(source = "name",target = "tname"),
            @Mapping(source = "pwd",target = "tpwd")
    })

3.配置拷贝策略

默认mapstruct使用的浅拷贝,即子对象拷贝引用,通过以下配置深拷贝:

@Mapper(mappingControl = DeepClone.class)

4.转换器注入为bean

@Mapper(componentModel = "spring")
上一篇下一篇

猜你喜欢

热点阅读