【PlantUML】- 时序图

写在前面

本篇文章,我们来介绍一下PlantUML的时序图。这个相对类图来讲,比较简单,也不需要布局。读完文章,相信你就能实际操作了。


目录


一、基本概念

时序图,是我们梳理复杂系统交互或设计的一大法宝。概念不多解释,直接上示例。


二、具体步骤

1.环境说明

名称 说明
Windows Windows10
Intellij IDEA版本 Intellij IDEA 2019.2.3(Ultimate Edition)
PlantUML Integration IDEA插件 2.23.0

2.元素

以下为PlantUML脚本,

uml 复制代码
@startuml
title 时序图的元素

participant ac << (A,#A8DEDF) AbstractClass >>
participant interface << (I,#B4A7E3) Interface >>
participant class << (C,#ADD1B2) Class >>

participant Participant as P
participant "()非字母形式" as P2

actor       Actor       as A #red
boundary    Boundary    as B #blue
control     Control     as C
database    Database    as D
entity      Entity      as E order 3
collections Collections as C2 order 2
queue       Queue       as Q order 1
@enduml

效果,

3.语法

以下为PlantUML脚本,

uml 复制代码
@startuml
skinparam style strictuml
skinparam sequenceArrowThickness 2
skinparam roundcorner 20
skinparam sequenceParticipant underline
autoactivate on

title 时序图语法
actor User

participant "First Class" as A
note over A: 这是对First Class的注释

participant "Second Class" as B
note over B: 这是对Second Class的注释

participant "third Class" as C
note across: 这是跨越所有\n参与者的注释

participant "Last Class" as D
hnote across: 这是跨越所有\n参与者的注释


== 第一段逻辑 ==
A -> B: A请求B
note right
    这是对A->B请求的注释
end note

B -> C: B请求C
C -> C: C请求自身
return success

C --> B: C响应B

== 第二段逻辑 ==
B -> D: B请求D
D -> D: D请求自身
return success

D --> A: D响应A

@enduml

效果,

4.示例

以下为PlantUML脚本,

uml 复制代码
@startuml
skinparam style strictuml
autoactivate on
autonumber

title 时序图示例

==阶段1==
autonumber 1
Alice -> Bob: request
'Bob --> Alice:  Response
return response

==阶段2==
autonumber 1

alt 场景1
    Alice -> Bob: request
    Alice <-- Bob: response
end

alt#Gold #LightBlue 场景2
autonumber 1
    Alice -> Bob: request

else 场景2.1
    Alice <-- Bob: response
    Alice -> Bob: request
    Alice <-- Bob: response
'    return response

else #Pink 场景2.2
    loop 1000次
        Alice -> Bob: request
        return response
    end
end

group 自定义
autonumber
    Alice -> Bob: request
    Alice <-- Bob: response
end

@enduml

效果,

最后,分享以下个人比较喜欢的几种颜色,用于标识重要节点或流程。

复制代码
#Lime, #Cyan, #Silver, #Magenta, #EEE, #FFBBBB, #DarkSalmon

至此,你就可以开启时序图的征程了~


三、参考资料

PlantUML 序列图


写在后面

如果本文内容对您有价值或者有启发的话,欢迎点赞、关注、评论和转发。您的反馈和陪伴将促进我们共同进步和成长。


系列文章

【PlantUML】-类图
【PlantUML】-布局
【IDEA插件】- PlantUML integration-Can't find Graphviz

相关推荐
夏影孤灯1 天前
十七、统一建模语言 UML
系统架构·uml
-qOVOp-2 天前
zst-2001 历年真题 UML
uml
rolt5 天前
[pdf,epub]292页《分析模式》漫谈合集01-59提供下载
产品经理·架构师·uml·领域驱动设计
王燕龙(大卫)14 天前
uml类关系(实现、继承,聚合、组合,依赖、关联)
uml
光头颜17 天前
UML之序列图事件时刻与轨迹
软件工程·uml
斗转星移317 天前
Ubuntu20.04 中使用vscode中编辑查看PlantUML
linux·vscode·uml·plantuml
未定义.22118 天前
电子削铅笔刀顺序图详解:从UML设计到PlantUML实现
java·软件工程·uml
aiden:)18 天前
UML 活动图深度解析:以在线购物系统为例
软件工程·软件构建·uml
未定义.22119 天前
UML-网络媒体教学系统顺序图深度解析
软件工程·uml
aiden:)19 天前
UML 状态图:以共享汽车系统状态图为例
汽车·软件工程·软件构建·uml