导图社区 【计算机】plantuml官方文档完全脑图笔记-序列图
这是一篇关于【计算机】plantuml官方文档完全脑图笔记-序列图的思维导图,全面且系统地介绍了plantuml序列图的各个组成部分及其相关细节。
编辑于2025-10-05 18:54:45这是一篇关于【计算机】plantuml官方文档完全脑图笔记-序列图的思维导图,全面且系统地介绍了plantuml序列图的各个组成部分及其相关细节。
从汉朝到清朝,涵盖了多个朝代的统治时期。并且包含不同统治势力的年号。结构为朝代 -> 帝王 -> 年号 -> 起讫时间、使用年数,条理清晰、结构严谨。
Java Doc: SpringFramework_API_.6.1.6,Spring Framework的API提供了丰富的功能和接口,帮助开发者构建企业级Java应用程序。
社区模板帮助中心,点此进入>>
这是一篇关于【计算机】plantuml官方文档完全脑图笔记-序列图的思维导图,全面且系统地介绍了plantuml序列图的各个组成部分及其相关细节。
从汉朝到清朝,涵盖了多个朝代的统治时期。并且包含不同统治势力的年号。结构为朝代 -> 帝王 -> 年号 -> 起讫时间、使用年数,条理清晰、结构严谨。
Java Doc: SpringFramework_API_.6.1.6,Spring Framework的API提供了丰富的功能和接口,帮助开发者构建企业级Java应用程序。
plantuml序列图
gzh: 极客脑图
基本示例
@startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: Another authentication Response @enduml
参与者
声明参与者
participant
@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 Foo -> Foo1 : To actor Foo -> Foo2 : To boundary Foo -> Foo3 : To control Foo -> Foo4 : To entity Foo -> Foo5 : To database Foo -> Foo6 : To collections Foo -> Foo7: To queue @enduml
使用 as 关键字重命名参与者
声明的顺序将是(默认的) 显示顺序
actor(角色) boundary(边界) control(控制) entity(实体) database(数据库) collections(集合) queue(队列)
构造类型和圈点
@startuml participant "Famous Bob" as Bob << Generated >> participant Alice << (C,#ADD1B2) Testable >> Bob->Alice: First message @enduml
Position of the stereotypes
Top postion (by default)
@startuml skinparam stereotypePosition top participant A<<st1>> participant B<<st2>> A --> B : stereo test @enduml
Bottom postion
@startuml skinparam stereotypePosition bottom participant A<<st1>> participant B<<st2>> A --> B : stereo test @enduml
改变actor的样式
@startuml actor Alice actor Bob Alice -> Bob : hello hide footbox @enduml
@startuml skinparam actorStyle awesome actor Alice actor Bob Alice -> Bob : hello hide footbox @enduml
@startuml skinparam actorStyle Hollow actor Alice actor Bob Alice -> Bob : hello hide footbox @enduml
设置背景颜色
@startuml actor Bob #red ' The only difference between actor and participant is the drawing ' participant Alice participant "I have a really\nlong name" as L #99FF99 ' You can also declare: participant L as "I have a really\nlong name" #99FF99 ' Alice->Bob: Authentication Request Bob->Alice: Authentication Response Bob->L: Log transaction @enduml
设置显示顺序
@startuml participant Last order 30 participant Middle order 20 participant First order 10 @enduml
创建参与者
@startuml Bob -> Alice : hello create Other Alice -> Other : new create control String Alice -> String note right : You can also put notes! Alice --> Bob : ok @enduml
多行定义参与者
@startuml participant Participant [ =Title ---- ""打算"" ] participant Bob Participant -> Bob @enduml
在参与者中使用非字母
@startuml Alice -> "Bob()" : Hello "Bob()" -> "This is very\nlong" as Long 'same as "Bob()" -> Long as "This is very\nlong" Long --> "Bob()" : ok @enduml
使用引号来定义参与者
使用 as 关键字来给这些参与者一个别名
生命线
激活与撤销
activate、deactivate、destroy
@startuml participant User User -> A: DoWork activate A A -> B: << createRequest >> 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: << createRequest >> activate B B --> A: RequestCreated deactivate B deactivate A A -> User: Done deactivate A @enduml
自动激活关键字
@startuml autoactivate on alice -> bob : hello bob -> bob : self call bill -> bob #005500 : hello from thread 2 bob -> george ** : create return done in thread 2 return rc bob -> george !! : delete return success @enduml
返回
@startuml Bob -> Alice : hello activate Alice Alice -> Alice : some action return bye @enduml
激活、撤销和创建的快捷语法。
++ 激活目标(可选择在后面加上#color) -- 撤销激活源 ** 创建目标实例 !! 摧毁目标实例
@startuml alice -> bob ++ : hello bob -> bob ++ : self call bob -> bob ++ #005500 : hello bob -> george ** : create return done return rc bob -> george !! : delete return success @enduml
@startuml alice -> bob ++ : hello1 bob -> charlie --++ : hello2 charlie --> alice -- : ok @enduml
@startuml alice -> bob --++ #gold: hello bob -> alice --++ #gold: you too alice -> bob --: step1 alice -> bob : step2 @enduml
隐藏孤立参与者
@startuml participant Alice participant Bob participant Carol Alice -> Bob : hello @enduml
@startuml hide unlinked participant Alice participant Bob participant Carol Alice -> Bob : hello @enduml
移除脚注
@startuml A --> B @enduml
@startuml hide footbox A --> B @enduml
消息
组合消息
alt/else opt loop par break critical group
综合示例
@startuml Alice -> Bob: 认证请求 alt 成功情况 Bob -> Alice: 认证接受 else 某种失败情况 Bob -> Alice: 认证失败 group 我自己的标签 Alice -> Log : 开始记录攻击日志 loop 1000次 Alice -> Bob: DNS 攻击 end Alice -> Log : 结束记录攻击日志 end else 另一种失败 Bob -> Alice: 请重复 end @enduml
group
次级分组标签 后面紧跟着消息内容
@startuml Alice -> Bob: 认证请求 Bob -> Alice: 认证失败 group 我自己的标签 [我自己的标签2] Alice -> Log : 开始记录攻击日志 loop 1000次 Alice -> Bob: DNS攻击 end Alice -> Log : 结束记录攻击日志 end @enduml
给分组信息着色
@startuml Alice -> Bob: Authentication Request alt#Gold #LightBlue Successful case Bob -> Alice: Authentication Accepted else #Pink Failure Bob -> Alice: Authentication Rejected end @enduml
引用
@startuml participant Alice actor Bob ref over Alice, Bob : init Alice -> Bob : hello ref over Bob This can be on several lines end ref @enduml
给自己发消息
\n 换行
@startuml Alice -> Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext @enduml
@startuml Alice <- Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext @enduml
对消息序列编号
autonumber
start
@startuml autonumber Bob -> Alice : Authentication Request Bob <- Alice : Authentication Response autonumber 15 Bob -> Alice : Another authentication Request Bob <- Alice : Another authentication Response autonumber 40 10 Bob -> Alice : Yet another authentication Request Bob <- Alice : Yet another authentication Response @enduml
DecimalFormat
@startuml autonumber "<b>[000]" Bob -> Alice : Authentication Request Bob <- Alice : Authentication Response autonumber 15 "<b>(<u>##</u>)" Bob -> Alice : Another authentication Request Bob <- Alice : Another authentication Response autonumber 40 10 "<font color=red><b>Message 0 " Bob -> Alice : Yet another authentication Request Bob <- Alice : Yet another authentication Response @enduml
stop、resume、format
@startuml autonumber 10 10 "<b>[000]" Bob -> Alice : Authentication Request Bob <- Alice : Authentication Response autonumber stop Bob -> Alice : dummy autonumber resume "<font color=red><b>Message 0 " Bob -> Alice : Yet another authentication Request Bob <- Alice : Yet another authentication Response autonumber stop Bob -> Alice : dummy autonumber resume 1 "<font color=blue><b>Message 0 " Bob -> Alice : Yet another authentication Request Bob <- Alice : Yet another authentication Response @enduml
分隔符
@startuml autonumber 1.1.1 Alice -> Bob: Authentication request Bob --> Alice: Response autonumber inc A 'Now we have 2.1.1 Alice -> Bob: Another authentication request Bob --> Alice: Response autonumber inc B 'Now we have 2.2.1 Alice -> Bob: Another authentication request Bob --> Alice: Response autonumber inc A 'Now we have 3.1.1 Alice -> Bob: Another authentication request autonumber inc B 'Now we have 3.2.1 Bob --> Alice: Response @enduml
%autonumber%
@startuml autonumber 10 Alice -> Bob note right the <U+0025>autonumber<U+0025> works everywhere. Here, its value is ** %autonumber% ** end note Bob --> Alice: //This is the response %autonumber%// @enduml
延迟
@startuml Alice -> Bob: 认证请求 ... Bob --> Alice: 认证响应 ...5分钟后... Bob --> Alice: 再见! @enduml
空间
@startuml Alice -> Bob: message 1 Bob --> Alice: ok ||| Alice -> Bob: message 2 Bob --> Alice: ok ||45|| Alice -> Bob: message 3 Bob --> Alice: ok @enduml
进入、发出
进入和发出消息
@startuml [-> A: DoWork activate A A -> A: Internal call activate A A ->] : << createRequest >> A<--] : RequestCreated deactivate A [<- A: Done deactivate A @enduml
@startuml participant Alice participant Bob #lightblue Alice -> Bob Bob -> Carol ... [-> Bob [o-> Bob [o->o Bob [x-> Bob ... [<- Bob [x<- Bob ... Bob ->] Bob ->o] Bob o->o] Bob ->x] ... Bob <-] Bob x<-] @enduml
缩短的进入信息与发出信息箭头
?
@startuml ?-> Alice : ""?->""\n**short** to actor1 [-> Alice : ""[->""\n**from start** to actor1 [-> Bob : ""[->""\n**from start** to actor2 ?-> Bob : ""?->""\n**short** to actor2 Alice ->] : ""->]""\nfrom actor1 **to end** Alice ->? : ""->?""\n**short** from actor1 Alice -> Bob : ""->"" \nfrom actor1 to actor2 @enduml
锚点和持续时间
@startuml !pragma teoz true {start} Alice -> Bob : start doing things during duration Bob -> Max : something Max -> Bob : something else {end} Bob -> Alice : finish {start} <-> {end} : some time @enduml
并行信息
(使用 teoz)
@startuml !pragma teoz true Alice -> Bob : hello & Bob -> Charlie : hi @enduml
对齐
@startuml skinparam sequenceMessageAlign right Bob -> Alice : Request Alice -> Bob : Response @enduml
箭头上的文本对齐可以用 skinparam sequenceMessageAlign , 后接参数 left , right 或 center
换行
@startuml participant a participant b a -> b :这\n一条\n是\n手动换行 @enduml
@startuml skinparam maxMessageSize 20 participant a participant b a -> b :this is a very long message on several words @enduml
此方式暂不支持中文换行
备注
注释信息
位置
note left、note right
@startuml Alice->Bob : hello note left: this is a first note Bob->Alice : ok note right: this is another note Bob->Bob : I am thinking note left a note can also be defined on several lines end note @enduml
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
可以通过修改 背景色 来高亮显示注释
note across
在多个参与者添加备注
@startuml Alice->Bob:m1 Bob->Charlie:m2 note over Alice, Charlie: 旧方法:""note over"" @endtuml
旧方法
@startuml Alice->Bob:m1 Bob->Charlie:m2 note across: 新方法:""note across"" @enduml
/
在同一级对齐多个备注
@startuml note over Alice : Alice的初始状态 note over Bob : Bob的初始状态 Bob -> Alice : hello @enduml
@startuml note over Alice : Alice的初始状态 / note over Bob : Bob的初始状态 Bob -> Alice : hello @enduml
样式
hnote、rnote
改变备注框的形状
@startuml caller -> server : conReq hnote over caller : 六边形 rnote over caller : 矩形 caller <- server : conConf @enduml
格式
simple
@startuml participant Alice participant "The **Famous** Bob" as Bob Bob -> Alice : ok note left This is **bold** This is //italics// This is ""monospaced"" This is --stroked-- This is __underlined__ This is ~~waved~~ end note @enduml
Creole和HTML
Use creole syntax to style your texts
@startuml participant Alice participant "The **Famous** Bob" as Bob Alice -> Bob : hello --there-- note right of Alice This is <back:cadetblue><size:18>displayed</size></back> __left of__ Alice. end note note left of Bob <u:red>This</u> is <color #118888>displayed</color> **<color purple>left of</color> <s:red>Alice</strike> Bob**. end note note over Alice, Bob <w:#FF33FF>This is hosted</w> by <img sourceforge.jpg> end note @enduml
箭头
改变箭头样式
@startuml Bob ->x Alice Bob -> Alice Bob ->> Alice Bob -\ Alice Bob \\- Alice Bob //-- Alice Bob ->o Alice Bob o\\-- Alice Bob <-> Alice Bob <->o Alice @enduml
x:表示丢失的信息 \、/:只拥有箭头的底部或顶部部分 重复箭头头(例如>> 或// :拥有一个小的箭头 -- 而不是-:拥有一个点状箭头 o:在箭头头添加最后的 "o" <->:使用双向的箭头
修改箭头颜色
@startuml Bob -[#red]> Alice : hello Alice -[#0000FF]->Bob : ok @enduml
Slanted or odd arrows
顺序
@startuml A ->(10) B: text 10 B ->(10) A: text 10 A ->(10) B: text 10 A (10)<- B: text 10 @enduml
@startuml A ->(40) B++: Rq B -->(20) A--: Rs @enduml
并行
@startuml !pragma teoz true A ->(50) C: Starts\nwhen 'B' sends & B ->(25) C: \nBut B's message\n arrives before A's @enduml
@startuml !pragma teoz true S1 ->(30) S2: msg 1\n & S2 ->(30) S1: msg 2 note left S1: msg\nS2 to S1 & note right S2: msg\nS1 to S2 @enduml
附录:箭头类型大全
普通箭头
@startuml participant Alice as a participant Bob as b a -> b : ""-> "" a ->> b : ""->> "" a -\ b : ""-\ "" a -\\ b : ""-\\\\"" a -/ b : ""-/ "" a -// b : ""-// "" a ->x b : ""->x "" a x-> b : ""x-> "" a o-> b : ""o-> "" a ->o b : ""->o "" a o->o b : ""o->o "" a <-> b : ""<-> "" a o<->o b : ""o<->o"" a x<->x b : ""x<->x"" a ->>o b : ""->>o "" a -\o b : ""-\o "" a -\\o b : ""-\\\\o"" a -/o b : ""-/o "" a -//o b : ""-//o "" a x->o b : ""x->o "" @enduml
进入信息和发出信息(使用'[', ']')
进入信息(使用'[')
@startuml participant Alice as a participant Bob as b [-> b : ""[-> "" [->> b : ""[->> "" [-\ b : ""[-\ "" [-\\ b : ""[-\\\\"" [-/ b : ""[-/ "" [-// b : ""[-// "" [->x b : ""[->x "" [x-> b : ""[x-> "" [o-> b : ""[o-> "" [->o b : ""[->o "" [o->o b : ""[o->o "" [<-> b : ""[<-> "" [o<->o b : ""[o<->o"" [x<->x b : ""[x<->x"" [->>o b : ""[->>o "" [-\o b : ""[-\o "" [-\\o b : ""[-\\\\o"" [-/o b : ""[-/o "" [-//o b : ""[-//o "" [x->o b : ""[x->o "" @enduml
发出信息(使用']')
@startuml participant Alice as a participant Bob as b [-> b : ""[-> "" [->> b : ""[->> "" [-\ b : ""[-\ "" [-\\ b : ""[-\\\\"" [-/ b : ""[-/ "" [-// b : ""[-// "" [->x b : ""[->x "" [x-> b : ""[x-> "" [o-> b : ""[o-> "" [->o b : ""[->o "" [o->o b : ""[o->o "" [<-> b : ""[<-> "" [o<->o b : ""[o<->o"" [x<->x b : ""[x<->x"" [->>o b : ""[->>o "" [-\o b : ""[-\o "" [-\\o b : ""[-\\\\o"" [-/o b : ""[-/o "" [-//o b : ""[-//o "" [x->o b : ""[x->o "" @enduml
短进入信息和短发出信息(使用'?')
短进入信息(使用'?')
@startuml participant Alice as a participant Bob as b [-> b : ""[-> "" [->> b : ""[->> "" [-\ b : ""[-\ "" [-\\ b : ""[-\\\\"" [-/ b : ""[-/ "" [-// b : ""[-// "" [->x b : ""[->x "" [x-> b : ""[x-> "" [o-> b : ""[o-> "" [->o b : ""[->o "" [o->o b : ""[o->o "" [<-> b : ""[<-> "" [o<->o b : ""[o<->o"" [x<->x b : ""[x<->x"" [->>o b : ""[->>o "" [-\o b : ""[-\o "" [-\\o b : ""[-\\\\o"" [-/o b : ""[-/o "" [-//o b : ""[-//o "" [x->o b : ""[x->o "" @enduml
短发出信息(使用'?')
@startuml participant Alice as a participant Bob as b [-> b : ""[-> "" [->> b : ""[->> "" [-\ b : ""[-\ "" [-\\ b : ""[-\\\\"" [-/ b : ""[-/ "" [-// b : ""[-// "" [->x b : ""[->x "" [x-> b : ""[x-> "" [o-> b : ""[o-> "" [->o b : ""[->o "" [o->o b : ""[o->o "" [<-> b : ""[<-> "" [o<->o b : ""[o<->o"" [x<->x b : ""[x<->x"" [->>o b : ""[->>o "" [-\o b : ""[-\o "" [-\\o b : ""[-\\\\o"" [-/o b : ""[-/o "" [-//o b : ""[-//o "" [x->o b : ""[x->o "" @enduml
盒子
Mainframe
@startuml mainframe This is a **mainframe** Alice->Bob : Hello @enduml
box
包裹参与者
@startuml box "Internal Service" #LightBlue participant Bob participant Alice end box participant Other Bob -> Alice : hello Alice -> Other : hello @enduml
填充区设置
@startuml skinparam ParticipantPadding 20 skinparam BoxPadding 10 box "Foo1" participant Alice1 participant Alice2 end box box "Foo2" participant Bob1 participant Bob2 end box Alice1 -> Bob1 : hello Alice1 -> Out : out @enduml
其他
页面标题、页眉和页脚
@startuml header Page Header footer Page %page% of %lastpage% title Example Title Alice -> Bob : message 1 Alice -> Bob : message 2 @enduml
更多标题信息
creole 格式
@startuml title __Simple__ **communication** example Alice -> Bob: Authentication Request Bob -> Alice: Authentication Response @enduml
多行
@startuml title __Simple__ communication example\non several lines Alice -> Bob: Authentication Request Bob -> Alice: Authentication Response @enduml
@startuml title <u>Simple</u> communication example on <i>several</i> lines and using <font color=red>html</font> This is hosted by <img:sourceforge.jpg> end title Alice -> Bob: Authentication Request Bob -> Alice: Authentication Response @enduml
分割示意图
@startuml Alice -> Bob : message 1 Alice -> Bob : message 2 newpage Alice -> Bob : message 3 Alice -> Bob : message 4 newpage A title for the\nlast page Alice -> Bob : message 5 Alice -> Bob : message 6 @enduml
分隔符
@startuml == 初始化 == Alice -> Bob: 认证请求 Bob --> Alice: 认证响应 == 重复 == Alice -> Bob: 认证请求 Alice <-- Bob: 认证响应 @enduml
外观参数(skinparam)
特定外观参数
默认情况下
@startuml Bob -> Alice : hello Alice -> Bob : ok @enduml
生命线策略
nosolid 虚线
(默认情况)
@startuml skinparam lifelineStrategy nosolid Bob -> Alice : hello Alice -> Bob : ok @enduml
solid 实线
@startuml skinparam lifelineStrategy solid Bob -> Alice : hello Alice -> Bob : ok @enduml
style strictuml
@startuml skinparam style strictuml Bob -> Alice : hello Alice -> Bob : ok @enduml
@startuml skinparam sequenceArrowThickness 2 skinparam roundcorner 20 skinparam maxmessagesize 60 skinparam sequenceParticipant underline actor User participant "First Class" as A participant "Second Class" as B participant "Last Class" as C User -> A: DoWork activate A A -> B: Create Request activate B B -> C: DoWork activate C C --> B: WorkDone destroy C B --> A: Request Created deactivate B A --> User: Done deactivate A @enduml
@startuml skinparam backgroundColor #EEEBDC skinparam handwritten true skinparam sequence { ArrowColor DeepSkyBlue ActorBorderColor DeepSkyBlue LifeLineBorderColor blue LifeLineBackgroundColor #A9DCDF ParticipantBorderColor DeepSkyBlue ParticipantBackgroundColor DodgerBlue ParticipantFontName Impact ParticipantFontSize 17 ParticipantFontColor #A9DCDF ActorBackgroundColor aqua ActorFontColor DeepSkyBlue ActorFontSize 17 ActorFontName Aapex } actor User participant "First Class" as A participant "Second Class" as B participant "Last Class" as C User -> A: DoWork activate A A -> B: Create Request activate B B -> C: DoWork activate C C --> B: WorkDone destroy C B --> A: Request Created deactivate B A --> User: Done deactivate A @enduml