惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyberwarzone
Cyberwarzone
V
Vulnerabilities – Threatpost
T
Tenable Blog
Forbes - Security
Forbes - Security
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Visual Studio Blog
WordPress大学
WordPress大学
Latest news
Latest news
K
Kaspersky official blog
T
Tailwind CSS Blog
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
C
Cisco Blogs
博客园 - 聂微东
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
小众软件
小众软件
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
S
SegmentFault 最新的问题
Security Latest
Security Latest
Y
Y Combinator Blog
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
P
Privacy & Cybersecurity Law Blog
L
LINUX DO - 最新话题
月光博客
月光博客
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
S
Security Affairs
P
Proofpoint News Feed
D
DataBreaches.Net
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG

博客园 - 正怒月神

windows 安装 openclaw docker-compose 启动 elk linux mysql 备份 maven 打包时优先选择本地仓库 nginx 部署2个相同的vue minio 设置IP MapStruct-plus cannot find converter from jenkins pipeline 发布 jar并运行 Easy es问题总结 Logstash docker发布 Docker 无法拉取 springmvc 多事务提交和回滚 springMvc 配置 UReport2 java 通过 microsoft graph 调用outlook(三) JPA Example 默认 join jackson.dataformat.xml 反序列化 对象中包含泛型 OR-TOOL 背包算法 解决JIRA、Confluence自动注销登录的问题 java 通过 microsoft graph 调用outlook(二)
MapperStruct 嵌套模型中 List<> 转 List<String>
正怒月神 · 2024-07-26 · via 博客园 - 正怒月神

废话不多说,上代码

宗旨:将List<A> 映射为 List<String>

一,实体类

Source

//Source中有一个List<A>
public class Source{
    private String id;
    private String from;
    private List<A> toRecipients;
 
}
 
//A对象中有个B
public class A{
    private B b;
}
 
//B有个address属性
public class B{
   private String address;
}

Target

public class Target {
    private String id;
    private String from;
    private List<String> to;
}

二,Mapper映射接口

 
import com.microsoft.graph.models.Message;
import com.microsoft.graph.models.Recipient;
import io.github.linpeilie.BaseMapper;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;
 
import javax.xml.transform.Source;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author: Tyler
 * @create: 2024-07-26
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface MyMapper {
    MyMapper INSTANCE = Mappers.getMapper(MyMapper.class);
 
    @Mappings({
        @Mapping(source = "id", target = "id"),
        @Mapping(source = "from", target = "from"),
        @Mapping(source = "toRecipients", target = "to"),
    })
        //实体转换
    Target convert(Source entity);
 
    //List转换
    List<MyMapper> convertList(List<Source> entitys);
 
    //自定义 List<A> 映射 List<String>
    default List<String> convertToString(List<A> entitys) {
        List<String> list=entitys.stream().map(x->x.getB().getAddress()).collect(Collectors.toList());;
        return list;
    }
 
}

三,调用

List<Target> list = MyMapper.INSTANCE.convertList(List<Source>);