V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Vimax
V2EX  ›  Java

调用远程接口返回多层级对象,应该放在哪个分层领域模型下比较合理?

  •  1
     
  •   Vimax · Aug 19, 2020 · 2386 views
    This topic created in 2078 days ago, the information mentioned may be changed or developed.

    假设调用远程接口放回 school 对象,school 对象下包含 student 和 teacher 对象。

    • School
      • Student
      • Teacher

    现有系统的分层领域模型有:

    • po
    • bo
    • dto
    • vo

    现有的对象都是放在分层领域模型包下,并以各自后缀大写结尾。

    使用远程接口调用放回 school 对象,接收的 school 对象放在 dto 下,那 school 里面的对象 student 和 teacher 也应该放在 dto 下吗?

    如果 student 和 teacher 分别定义 studentDTO 和 teacherDTO,则使用 restTemplate.getForObject 接收 student 和 teacher 则不能直接绑定上。

    如果后面不加 DTO 而将对象放在 dto 包下,code review 的时候又不符合 DTO 结尾规范。

            SchoolDTO school = this.restTemplate.getForObject(invokeUrl, SchoolDTO.class);
    
    5 replies    2020-08-19 22:28:49 +08:00
    lidlesseye11
        1
    lidlesseye11  
       Aug 19, 2020
    “如果 student 和 teacher 分别定义 studentDTO 和 teacherDTO,则使用 restTemplate.getForObject 接收 student 和 teacher 则不能直接绑定上。”
    为啥?
    Kirsk
        2
    Kirsk  
       Aug 19, 2020 via Android
    Data transition object
    Vimax
        3
    Vimax  
    OP
       Aug 19, 2020
    @lidlesseye11 如果对方传过来的是 student 和 teacher,我用 studentDTO 和 teacherDTO 接收,结果都是 Null 。同名的情况下则可以绑定上数据。用的是 restTemplate.getForObject.
    Vimax
        4
    Vimax  
    OP
       Aug 19, 2020
    @Kirsk 全部都用 dto 吗?
    Kirsk
        5
    Kirsk  
       Aug 19, 2020
    @Vimax 你在楼上说了 既然是 null 你只能不用 DTO 一般情况是 DTO 的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3269 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 14:07 · PVG 22:07 · LAX 07:07 · JFK 10:07
    ♥ Do have faith in what you're doing.