为了便捷地使用PlantUML,许多流行的IDE和代码编辑器提供了集成PlantUML的插件,如Visual Studio Code、IntelliJ IDEA、Eclipse等。插件提供了实时预览、语法高亮和图表导出等功能,能帮助我们更快捷,更高效地画图,整体上IDEA的插件用起来体验最好,但是IDEA大家懂的,太占内存了,VS Code相对而言,用起来就会轻量很多。
IntelliJ IDEA:比如 "PlantUML integration" 可以让我们直接在 IDE 中查看和编辑 PlantUML 图表
插件使用效果
VS Code:https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml
@startuml participant Participant as Foo actor Actor as Foo1 boundary Boundary as Foo2 control Control as Foo3 entity Entity as Foo4 database Database as Foo5 collections Collections as Foo6 queue Queue as Foo7 @enduml
默认的颜色比较单调,也可以通过
#
来设置参与者的颜色:
@startuml actor Bob #blue ' The only difference between actor 'and participant is the drawing participant Alice #SkyBlue participant "I have a really\nlong name" as L #00ff00
@startuml participant User User -> A: DoWork activate A A -> B: <> activate B B -> C: DoWork activate C C --> B: WorkDone destroy C B --> A: RequestCreated deactivate B A -> User: Done deactivate A @enduml
生命线的嵌套与颜色:我们还可以使用嵌套激活条来表示内部调用,并可以给生命线添加颜色。
@startuml participant User User -> A: DoWork activate A #FFBBBB A -> A: Internal call activate A #DarkSalmon A -> B: <> activate B B --> A: RequestCreated deactivate B deactivate A A -> User: Done deactivate A @enduml
自动激活:在发送消息时自动显示激活条。
A->B++: 激活B并发送消息
自动去激活:在接收回应时自动隐藏激活条。
A->B++: 激活B并发送消息 A
分组和替代
分组:用于逻辑上分组一系列交互。
group 分组名 A -> B: 消息 ... end group
替代(Alt/Else):表示基于条件的替代执行流程。
alt 条件1 A -> B: 满足条件1的消息 else 条件2 A -> B: 满足条件2的消息 end
注释
注释用于添加说明性文本。
可以用note left of,note right of或note over来控制注释相对节点的位置,还可以通过修改背景色来高亮显示注释。
@startuml participant Alice participant Bob note left of Alice #aqua This is displayed left of Alice. end note
note right of Alice: This is displayed right of Alice.
note over Alice: This is displayed over Alice.
note over Alice, Bob #FFAAAA: This is displayed\n over Bob and Alice.
note over Bob, Alice This is yet another example of a long note. end note @enduml