常用注解
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")
网友评论