mocxe2vwww
V2EX  ›  Java

POJO 对象各种嵌套, 有什么办法通用的处理?

  •  
  •   mocxe2vwww · Sep 1, 2020 · 2912 views
    This topic created in 2104 days ago, the information mentioned may be changed or developed.

    很多 VO 对象都关联了其他 VO 对象。

    class UserVO {

    OrgVO org;
    

    }

    项目中很多这样的 VO,比如在 userVOList 列表中,都得循环去关联 OrgVO, controller 中到处都是 for 循环 设置关联对象,很多重复的代码

    有什么好的办法通用的处理

    2 replies    2020-09-14 15:01:03 +08:00
    dogfeet
        1
    dogfeet  
       Sep 1, 2020
    说的是 POJO 麻烦,还是 Dto 与 Vo 转换的麻烦?
    POJO 嵌套可以用 lombok 嘛。
    至于 Dto Vo 转换这种,MapStruct 了解一下。
    https://github.com/mapstruct/mapstruct-examples
    这里面的:mapstruct-mapping-with-cycles 、mapstruct-nested-bean-mappings 2 个例子应该是你感兴趣的。
    mocxe2vwww
        2
    mocxe2vwww  
    OP
       Sep 14, 2020 via iPhone
    @dogfeet 谢谢 这个可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1133 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 18:09 · PVG 02:09 · LAX 11:09 · JFK 14:09
    ♥ Do have faith in what you're doing.