【问题标题】:How to include classes from another Plantuml file into a class diagram?如何将另一个 Plantuml 文件中的类包含到类图中?
【发布时间】:2021-05-10 16:42:08
【问题描述】:

我在 PlantUML 中有两个类图,想在一个文件中定义一个类并在另一个文件中重用它。请参阅下面的示例。

diagram1.puml:

@startuml diagram1

class "Foo" as foo {
 ...attributes
}

@enduml

和图2:

@startuml diagram2

!include diagram1!foo

class "Bar" as bar {
 ...attributes
}

@enduml

现在我的期望是 diagram2 将在图中显示 Foo 和 Bar 类。但是,包含的类没有显示在渲染中。

如何解决?

【问题讨论】:

  • 您是否收到错误消息?从第一个图中删除 @startuml 和 @enduml 会发生什么?
  • @albert 我没有收到错误消息。我只是在视觉上看不到任何东西。当我删除 @startuml 和 @enduml 时,它确实有效!
  • 据我所知,include 语句包含的代码就好像它是在那个包含的地方输入的一样,所以我可以想象原来的代码不起作用。
  • 如果您将其作为答案发布,那么我可以为您接受。

标签: plantuml


【解决方案1】:

plantuml 包含语句包含代码,就好像它是在该包含位置键入的一样(例如 C / C++ 等的包含文件也是如此)。所以代码应该是这样的: 对于图 2:

@startuml diagram2

!include diagram1!foo

class "Bar" as bar {
 ...attributes
}

@enduml

对于图表1

class "Foo" as foo {
 ...attributes
}

当您还想将图表 1 显示为单独的文件时,您必须添加一个额外的文件:

@startuml diagram1_show

!include diagram1!foo

@enduml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-29
    • 2020-01-20
    • 2011-11-24
    • 2017-04-06
    • 2011-10-09
    • 1970-01-01
    • 2019-12-09
    相关资源
    最近更新 更多