日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PlantUML权威教程-时序图

發布時間:2025/3/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PlantUML权威教程-时序图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • PlantUML
    • 時序圖
      • 簡單的時序圖
      • participant改變先后順序
      • 使用as重命名參與者
      • order改變參與者的順序
      • 使用非字母符號
      • 修改箭頭樣式
      • 修改箭頭的箭頭的顏色
      • 對消息序列進行編號
      • 組合消息
      • 添加注釋
      • 改變注釋的形狀
      • 使用ref實現引用
      • 延時效果
      • 使用`|||`增加空間像素
      • 生命線的開始和撤銷
      • 生命線的嵌套
      • 創建參與者
      • 進入和發出消息
      • 構造類型和圈點
      • 多行標題
      • hide footbox
      • 增加外觀參數

PlantUML

時序圖

簡單的時序圖

@startuml simple ' 你可以用 -> 來繪制參與者之間傳遞的消息,而不必顯式地聲明參與者。 ' 你也可以使用 --> 繪制一個虛線箭頭。 ' 另外,你還能用 <- 和 <--,這不影響繪圖,但可以提高可讀性。注意:僅適用于時序圖,對于其它示意 ' 圖,規則是不同的。Alice -> Bob: Authentication Request Bob --> Alice: Authentication ResponseAlice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response@enduml

participant改變先后順序

關鍵字 participant 用于改變參與者的先后順序。
你也可以使用其它關鍵字來聲明參與者:
? actor
? boundary
? control
? entity
? database

@startuml participantactor Foo1 boundary Foo2 control Foo3 entity Foo4 database Foo5 collections Foo6 Foo1 -> Foo2 : To boundary Foo1 -> Foo3 : To control Foo1 -> Foo4 : To entity Foo1 -> Foo5 : To database Foo1 -> Foo6 : To collections@enduml

使用as重命名參與者

@startuml sequence_as 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

order改變參與者的順序

? 使用order改變參與者的順序,order的順序越小越靠前

@startuml sequence_order ' 通過order 定義參與者順序 participant Last order 30 participant Middle order 20 participant First order 10 @enduml

使用非字母符號

@startuml sequence_no_alphabet ' 引號中可以使用非字母符號 ' 你可以使用引號定義參與者,還可以使用關鍵字 as 給參與者定義別名 Alice -> "Bob()" : Hello "Bob()" -> "This is very\nlong" as Long ' You can also declare: ' "Bob()" -> Long as "This is very\nlong" Long --> "Bob()" : ok@enduml

修改箭頭樣式

? 使用不同樣式的箭頭

@startuml arrow_num' ? 表示一條丟失的消息:末尾加 x ' ? 讓箭頭只有上半部分或者下半部分:將 <> 替換成 \ 或者 / ' ? 細箭頭:將箭頭標記寫兩次 (如 >> 或 //) ' ? 虛線箭頭:用 -- 替代 - ' ? 箭頭末尾加圈:->o ' ? 雙向箭頭:<->Bob ->x Alice : 末尾加 x Bob -> Alice : 常規箭頭 Bob ->> Alice : 細箭頭 Bob -\ Alice : 粗箭頭只保留上半部分 Bob \\- Alice : 細箭頭 只保留下半部分 Bob //-- Alice : 細箭頭只保留上半部分 Bob ->o Alice : 實線箭頭 帶圓圈 Bob o\\-- Alice : 虛線細箭頭 只保留一半 帶圓圈 Bob <-> Alice : 雙向實線箭頭 Bob <->o Alice : 雙向實線箭頭 右側帶圓圈@enduml

修改箭頭的箭頭的顏色

@startuml change_arrow_color Bob -[#red]> Alice : hello Alice -[#0000FF]->Bob : ok @enduml

對消息序列進行編號

@startuml autonumber autonumber Bob -> Alice : Authentication Request Bob <- Alice : Authentication Response @enduml

@startuml autonumber_start_increment' 語句 autonumber start 用于指定編號的初始值,而 autonumber start increment 可以同時指定編號 ' 的初始值和每次增加的值。 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

在雙引號中指定編號的方式

? 可以使用html的方式指定

@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

@startuml autonumber_stop 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 alt ' 我們可以通過以下關鍵詞將組合消息: ' ? alt/else ' ? opt ' ? loop ' ? par ' ? break ' ? critical ' ? group, 后面緊跟著消息內容 ' 可以在標頭 (header) 添加需要顯示的文字 (group 除外)。 ' 關鍵詞 end 用來結束分組。 ' 注意,分組可以嵌套使用 Alice -> Bob: Authentication Request alt successful case Bob -> Alice: Authentication Accepted else some kind of failure Bob -> Alice: Authentication Failure group My own label Alice -> Log : Log attack start loop 1000 times Alice -> Bob: DNS Attack end Alice -> Log : Log attack end end else Another type of failure Bob -> Alice: Please repeat end @enduml

添加注釋

我們可以使用note left或者note right的形式為時序圖添加注釋,使用end note添加多行注釋

@startuml sequence_with_notes 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

@startuml note_over ' 可以使用 note left of,note right of 或 note over 在節點 (participant) 的相對位置放置注釋。 ' 還可以通過修改背景色來高亮顯示注釋。 ' 以及使用關鍵字 end note 來添加多行注釋 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

改變注釋的形狀

@startuml rnote_hnote ' 你可以使用 hnote 和 rnote 這兩個關鍵字來修改備注框的形狀 caller -> server : conReq hnote over caller : idle caller <- server : conConf rnote over server "r" as rectangle "h" as hexagon end rnote @enduml

使用ref實現引用

@startuml ref participant Alice actor Bob ref over Alice, Bob : init Alice -> Bob : hello ref over Bob This can be on several lines end ref @enduml

延時效果

@startuml delay ' 你可以使用... 來表示延遲,并且還可以給延遲添加注釋 Alice -> Bob: Authentication Request ... Bob --> Alice: Authentication Response ...5 minutes latter... Bob --> Alice: Bye ! @enduml

使用|||增加空間像素

@startuml spqce ' 你可以使用 ||| 來增加空間。 ' 還可以使用數字指定增加的像素的數量。 Alice -> Bob: message 1 Bob --> Alice: ok ||| Alice -> Bob: message 2 Bob --> Alice: ok ||45|| Alice -> Bob: message 3 Bob --> Alice: ok @enduml

生命線的開始和撤銷

@startuml life_line 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 squence_lifeline 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 create_sequence ' 你可以把關鍵字 create 放在第一次接收到消息之前,以強調本次消息實際上是在創建新的對象 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 sequene_[] [-> A: DoWork activate A A -> A: Internal call activate A A ->] : << createRequest >> A<--] : RequestCreated deactivate A [<- A: Done deactivate A @enduml

@startuml [-> Bob [o-> Bob [o->o Bob [x-> Bob [<- Bob [x<- Bob Bob ->] Bob ->o] Bob o->o] Bob ->x] Bob <-] Bob x<-] @enduml

構造類型和圈點

@startuml color_sequence ' 可以使用 << 和 >> 給參與者添加構造類型。 ' 在構造類型中,你可以使用 (X,color) 格式的語法添加一個圓圈圈起來的字符participant "Famous Bob" as Bob << Generated >> participant Alice << (C,#ADD1B2) Testable >> Bob->Alice: First message @enduml

@startuml sequence_with_circle' 默認使用 guillemet 字符來顯示構造類型。你可以使用外觀參數 guillemet 來修改顯示行為。 skinparam guillemet false participant "Famous Bob" as Bob << Generated >> participant Alice << (C,#ADD1B2) Testable >>Bob->Alice: First message @enduml

@startuml new_circle participant Bob << (C,#ADD1B2) >> participant Alice << (C,#ADD1B2) >> Bob->Alice: First message @enduml

@startuml coreole title __Simple__ **communication** example Alice -> Bob: Authentication Request Bob -> Alice: Authentication Response @enduml


[外鏈圖片轉存失敗(img-JyPt3nSy-1564328385944)(/work/linux-sys/UML/out/時序圖/sequence_with_coreole/coreole.png)]

多行標題

@startuml title_endtitle 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

hide footbox

@startuml hide foot boot hide footbox title Footer removed Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response @enduml

增加外觀參數

用 skinparam 改變字體和顏色。
可以在如下場景中使用:
? 在圖示的定義中,
? 在引入的文件中,
? 在命令行或者 ANT 任務提供的配置文件中。
你也可以修改其他渲染元素,如以下示例:

@startuml skinparam skinparam sequenceArrowThickness 2 skinparam roundcorner 20 skinparam maxmessagesize 60 skinparam sequenceParticipant underlineactor 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 sikin 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

@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

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的PlantUML权威教程-时序图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。