当前位置:网站首页>plantuml介绍与使用
plantuml介绍与使用
2022-07-01 21:43:00 【birdyson】
介绍
好用的免费画图插件,兼容vscode、IDEA等大牌IDE,使用编写代码的方式自动生成UML图形。官方中文文档:https://plantuml.com/zh/
安装方式
以IDEA为例,直接在Plugin -> Marketplace中安装即可,vscode同理。
入门
在文件目录中新建文件,可以看到PlantUML File,新建此文件,选中你需要的UML图形。
UML绘图语法规则
全局规则
作用域
puml需要将代码写在@startuml与@enduml之间才能生效。
顺序图
箭头
@startuml
Client -> Server: 建立连接
' ↓这里为了可读性也可以反过来写成: <--
Server --> Client: 数据交互
Client --> Server: 数据交互
Server -> Client: 断开连接
@enduml

箭头样式:
| No | 字段 | 表示 |
|---|---|---|
| 1 | x | 丢失信息,箭头尾处为x |
| 2 | > | 实心箭头 |
| 3 | >> | 虚心箭头 |
| 4 | - | 实线 |
| 5 | – | 虚线 |
| 6 | <-> | 双向箭头 |
声明参与者
可以通过声明参与者的方式,为参与者更改属性、赋予别名as(一旦赋予别名后续不可再使用原名)、设置权重order(数量越小越靠前)。
@startuml
participant Client as c order 1
participant Server as s order 2
c -> s: 建立连接
s --> c: 数据交互
c --> s: 数据交互
s -> c: 断开连接
@enduml
可以使用的参与者属性:
| No | 字段 | 表示 |
|---|---|---|
| 1 | participant | 参与者 |
| 2 | actor | 角色 |
| 3 | control | 控制 |
| 4 | entity | 实体 |
| 5 | database | 数据库 |
| 6 | collections | 集合 |
| 7 | queue | 队列 |
| 8 | boundary | 边界 |

文字对齐
skinparam sequenceMessageAlign center
消息序号
autonumber 1.1,指定自增数字,默认增加最后一个数字,可指定自增数字位。
@startuml
'https://plantuml.com/sequence-diagram
participant Client as c order 1
participant Server as s order 2
autonumber 1.1
c -[#red]> s: 建立连接
autonumber inc A
s --> c: 数据交互
c --> s: 数据交互
autonumber inc A
s -> c: 断开连接
@enduml

注释
note left:、 note right: 单行注释或者使用 note left ... endnote多行注释。

分隔符
== 重复 ==或... 重复 ...

间距
|||设置间距,或指定间距||45||

生命线
activate c初始化生命,deactivate c结束生命线,可以嵌套使用。

返回
生命线可以返回内容,使用return返回,同时可以配合autoactivate实现自动生命线声明与销毁。
快捷创建、销毁、生命线/实例
@startuml
alice -> bob ++ : hello
bob -> bob ++ : self call
bob -> bib ++ #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

活动图
箭头
-->代表普通箭头-[labels]->代表带标签的箭头-left->指定方向的箭头(down, up, left, right)
开始与结束
(*)开始/结束start/stop开始/结束
边栏推荐
- 多种智能指针
- Icml2022 | interventional contrastive learning based on meta semantic regularization
- 杰理之蓝牙耳机品控和生产技巧【篇】
- linux下清理系统缓存并释放内存
- LIS (longest ascending subsequence) problem that can be understood [easy to understand]
- 面试题:MySQL的union all和union有什么区别、MySQL有哪几种join方式(阿里面试题)[通俗易懂]
- Show member variables and methods in classes in idea
- The difference between NiO and traditional IO
- 杰理之、产线装配环节【篇】
- burpsuite简单抓包教程[通俗易懂]
猜你喜欢
随机推荐
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
Unity uses SQLite
Use of vscode
杰理之蓝牙耳机品控和生产技巧【篇】
Design and practice of new generation cloud native database
手动实现function isInstanceOf(child,Parent)
浏览器tab页之间的通信
Simple interactive operation of electron learning (III)
多种智能指针
Go - exe corresponding to related dependency
Fundamentals - IO intensive computing and CPU intensive computing
统计字符中每个字符出现的个数
MQ学习笔记
Test cancellation 1
地图其他篇总目录
十三届蓝桥杯B组国赛
Count the number of each character in the character
杰理之、产线装配环节【篇】
收到一封CTO来信,邀约面试机器学习工程师
AirServer手机第三方投屏电脑软件









