sequenceDiagram participant Alice participant Bob Alice->>Bob: Hi Bob Bob->>Alice: Hi Alice
1 2 3 4 5
sequenceDiagram participant Alice participant Bob Alice->>Bob: Hi Bob Bob->>Alice: Hi Alice
角色
如果您特别希望使用 actor 符号而不是带有文本的矩形,则可以通过使用 actor 语句来实现,如下所示。
1 2 3 4 5
sequenceDiagram actor Alice actor Bob Alice->>Bob: Hi Bob Bob->>Alice: Hi Alice
1 2 3 4 5
sequenceDiagram actor Alice actor Bob Alice->>Bob: Hi Bob Bob->>Alice: Hi Alice
别名
1 2 3 4 5
sequenceDiagram participant A as Alice participant J as John A->>J: Hello John, how are you? J->>A: Great!
1 2 3 4 5
sequenceDiagram participant A as Alice participant J as John A->>J: Hello John, how are you? J->>A: Great!
消息
消息可以是两个,可以实心显示或用虚线显示。
1
[Actor][Arrow][Actor]:Message text
类型
描述
->
不带箭头的实线
–>
不带箭头的虚线
->>
带箭头的实线
–>>
带箭头的虚线
-x
末端有十字的实线
–x
虚线末端带有十字
-)
末端有一个打开箭头的实线(异步)
–)
末尾带有打开箭头的虚线(异步)
注释
可以向串行图添加注释。这是通过注解[ right of | left of | over ] [Actor]: Text in note content来完成的
1 2 3
sequenceDiagram Alice->John: Hello John, how are you? Note over Alice,John: A typical interaction
1 2 3
sequenceDiagram Alice->John: Hello John, how are you? Note over Alice,John: A typical interaction
循环
1 2 3
loop Loop text ... statements ... end
示例
1 2 3 4 5
sequenceDiagram Alice->John: Hello John, how are you? loop Every minute John-->Alice: Great! end
1 2 3 4 5
sequenceDiagram Alice->John: Hello John, how are you? loop Every minute John-->Alice: Great! end
并行
可以显示并行发生的动作。
1 2 3 4 5 6 7
par [Action 1] ... statements ... and [Action 2] ... statements ... and [Action N] ... statements ... end
示例
1 2 3 4 5 6 7 8
sequenceDiagram par Alice to Bob Alice->>Bob: Hello guys! and Alice to John Alice->>John: Hello guys! end Bob-->>Alice: Hi Alice! John-->>Alice: Hi Alice!
1 2 3 4 5 6 7 8
sequenceDiagram par Alice to Bob Alice->>Bob: Hello guys! and Alice to John Alice->>John: Hello guys! end Bob-->>Alice: Hi Alice! John-->>Alice: Hi Alice!