MapStruct自动忽略未映射的属性 [英] MapStruct ignore automatically unmapped properties

查看:9777
本文介绍了MapStruct自动忽略未映射的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的代码中使用不同业务用例之间共享的大型模型(超过50个字段)的MapStruct。根据入口点,将映射一些属性,而不映射一些属性。当我构建项目时,我将始终获得警告:未映射的目标属性消息。

I am using MapStruct with big models (more than 50 fields) shared between different business use cases in my code. Depending on the entry point, some properties will be mapped and some not. When I build my project, I will always get the "WARNING: Unmapped target properties" message.

我研究并发现可以通过使用语义告诉mapstruct忽略该字段

I have researched and seen that it is possible to tell the mapstruct to ignore the field by using the semantic

@Mapping(target = "propName", ignore = true)



<问题是,考虑到我的对象有这么多字段,忽略每个映射器类中的每个单独属性需要大量代码。我也不希望在我的日志中出现此警告。有没有办法告诉mapstruct忽略未映射的内容,避免这条消息?

The problem is, given my objects with so many fields, it would take a lot of code to ignore each single property in each mapper class. I also do not want this Warning on my log. Is there any way to tell mapstruct to ignore what is not mapped, avoiding this message?

推荐答案

你可以设置未映射的目标策略在 @Mapper 级别或通过 @MapperConfig 分享多个映射器的设置:

You can set the "unmapped target policy" on the @Mapper level or via @MapperConfig to share a setting across several mappers:

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface MyMapper {}

这篇关于MapStruct自动忽略未映射的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆