首页 \ 问答 \ Mapstruct:将多个源对象映射到子对象(Mapstruct: Mapping multiple source objects to subobjects)

Mapstruct:将多个源对象映射到子对象(Mapstruct: Mapping multiple source objects to subobjects)

给出一组四个对象,如:

A{String one, B b}

B{String two, String three}

C{String one, String two}

D{String three}

我希望生成如下映射:

A cAndDToA(C c , D d);

我目前无法找到一种方法来填充A中的B对象与来自C和D的数据。

有没有人知道这个问题的解决方案,或者有更好的方法?


Given a set of four objects like:

A{String one, B b}

B{String two, String three}

C{String one, String two}

D{String three}

I wish to generate a mapping like:

A cAndDToA(C c , D d);

I cannot currently find a way to populate the B object inside of A with data from both C and D.

Does anyone know a solution to this issue, or have a better approach?


原文:https://stackoverflow.com/questions/35706928
更新时间:2023-06-25 19:06

最满意答案

此检查由gcc编译器处理,特别是对于scanf / printf函数。

这是一个常见错误,值得为编译器添加特殊案例代码以实现这些功能。

请参阅GCC -WFormat标志: http ://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html

-Wformat:检查对printf和scanf等的调用,以确保提供的参数具有适合指定格式字符串的类型,并且格式字符串中指定的转换是有意义的。 这包括标准函数,以及printf,scanf,strftime和strfmon(X / Open扩展,而不是C标准)系列中格式属性(参见函数属性)指定的其他函数。

所有编译器都没有实现这些检查,因此肯定不能依赖它们。

使用GCC,您可以使用函数属性 'format'和'format-arg'告诉编译器对您的函数应用相同的检查。

format(archetype,string-index,first-to-check)format属性指定函数采用printf,scanf,strftime或strfmon样式参数,这些参数应根据格式字符串进行类型检查。 例如,声明:

extern int my_printf (void *my_object, const char *my_format, ...)  
 __attribute__ ((format (printf, 2, 3)));

...导致编译器检查对my_printf的调用中的参数,以便与printf样式格式字符串参数my_format保持一致。


This check is handled by the gcc compiler, specifically for scanf/printf functions.

It's such a common error that it's worth adding special case code to the compiler for these functions.

see the GCC -WFormat flag here: http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html

-Wformat : Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified, and that the conversions specified in the format string make sense. This includes standard functions, and others specified by format attributes (see Function Attributes), in the printf, scanf, strftime and strfmon (an X/Open extension, not in the C standard) families.

These checks are not implemented by all compilers, so it's certainly not something to rely on.

With GCC you can use Function Attributes 'format' and 'format-arg' to tell the compiler to apply the same checks to your functions.

format (archetype, string-index, first-to-check) The format attribute specifies that a function takes printf, scanf, strftime or strfmon style arguments which should be type-checked against a format string. For example, the declaration:

extern int my_printf (void *my_object, const char *my_format, ...)  
 __attribute__ ((format (printf, 2, 3)));

...causes the compiler to check the arguments in calls to my_printf for consistency with the printf style format string argument my_format.

相关问答

更多
  • Cabal的main-is选项只告诉Cabal它应该传递给GHC的文件名。 Cabal并不关心它的模块名称。 GHC本身有一个标志,也称为-main-is , 在此记录,它告诉编译器哪个模块具有main功能。 这样可行: executable foo main-is: Foo.hs ghc-options: -main-is Foo 当然Foo.hs应该从module Foo where…开始module Foo where…和导出main 。 像往常一样,模块名称和文件名需要匹配。 这样,所有可 ...
  • 我认为,对指针来说也很新颖 nodeType *current, *trail, *newNode; 在这一点上,newNode没有任何价值,它'点'没有意义 newNode->info = item; 此时你使用newNode的无意义值。 这是你的编译器警告的。 你需要做的就是这样的事情 nodeType *current, *trail, *newNode; newNode = new nodeType(); // make newNode ...
  • 可能你想要这个? guard let status = dictionary["status"] as? String else { // status does not exist or is not a String } // status is a non-optional String Probably you want this? guard let status = dictionary["status"] as? String else { // status does n ...
  • 类似的问题: 什么是结构objc_class的methodLists属性? 根据上面的帖子和本文 ,Apple设计带有双指针的methodLists (对于OBJC2.0来说是相同的)的原因是,简单地说,双指针的结构在运行时将category方法添加到类的方法列表中更快。 由于双指针用于方法列表列表,因此请考虑每个类别都有一个方法列表,并且在运行时将一个或多个类别添加到类中,而不是逐个添加方法时,可以简单地将指针添加到类别方法列表中to methodLists ,它有一个指向每个列表/数组指针的指针。 我不 ...
  • 你问题是(并且编译器可能已经发出了关于此的警告)_buffer未初始化,这意味着它指向内存中的某个随机地址 - 因此您的运行时错误。 将您的代码更改为 char buffer [128]; char *_buffer=buffer; 和printf buffer (不是_buffer )。 you problem is (and the compiler has probably already issued a warning about this) _buffer is uninitialized, ...
  • 由于没有具体问题,我将就此问题提供一些一般性建议。 看起来你走在正确的轨道上。 您的方法是正确的,您需要遍历语法树并检查每个子表达式,如果您的类型不匹配则失败。 typecheckexp :: [TypeEnv] -> Exp -> Bool typecheckexp types (Add e1 e2) = case (te1, te2) of (Just TyInt, Just TyInt) -> True _ -> False where te1 = getTypeO ...
  • 由于您手动将3为Color ,编译器将允许您这样做。 如果您尝试使用没有强制转换的普通3初始化变量x ,您将获得诊断。 请注意,枚举可以存储的值范围不受其包含的枚举器的限制。 它是可以存储枚举的所有枚举器值的最小位域的值范围。 也就是说,枚举类型的范围是0..3 : 00 01 10 11 因此值3仍在范围内,因此代码有效。 如果你输出一个4 ,那么结果值将不会被C ++标准指定。 实际上,实现必须为枚举选择基础整数类型。 它可以选择的最小类型是char ,但它仍然能够至少存储高达127值。 但如上所述, ...
  • TreeNode::getInfo的签名返回T ,它是临时的。 您不想尝试分配给它,因为这将不起作用。 相反,调用TreeNode::setInfo将您的底层Token替换为您想要的那个。 The signature for TreeNode::getInfo returns T which is a temporary. You don't want to attempt to assign to it, because that will have no effect. Instead ...
  • 使用dynamic_cast ,从不输入: if (Van* item = dynamic_cast(a)) { item->doVanThings(); // do van things } //else try other casts 更好的是让多态分化,因为你已经在使用多态: class Auto { public: virtual void doThings() = 0; }; class Van : public Auto { public: void d ...
  • 此检查由gcc编译器处理,特别是对于scanf / printf函数。 这是一个常见错误,值得为编译器添加特殊案例代码以实现这些功能。 请参阅GCC -WFormat标志: http ://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html -Wformat:检查对printf和scanf等的调用,以确保提供的参数具有适合指定格式字符串的类型,并且格式字符串中指定的转换是有意义的。 这包括标准函数,以及printf,scanf,strftime ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。