# Puml 语法说明
Posted 爱码代码的喵
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了# Puml 语法说明相关的知识,希望对你有一定的参考价值。
Puml 语法说明
Idea 插件
Idea
安装PlantUML diagramming
、PlantUml Diagram Generator
Puml 官网地址
类图语法
属性可见性
public 用+表示
private 用-表示
protected 用#表示
package 用~表示
元素声明
abstract 抽象
abstract class 抽象(等同abstract)
annotation 注解
circle 圆
() 圆缩写形式
class 类
diamond 菱形
<> 菱形写形式
entity 实例
enum 枚举
interface 接口
类之间的关系
类型 | 符号 |
---|---|
扩展 | `< |
组成 | *-- |
聚合 | o-- |
- 关系代码
@startuml
'https://plantuml.com/class-diagram
left to right direction
'泛化和实现'
abstract class AbstractList extends AbstractCollection implements List
+ add():boolean
abstract class AbstractCollection<E> implements Collection
+ add():boolean
interface List<E> extends Collection
+ add():boolean
interface Collection
+ add():boolean
'关联'
class LoginForm
JButton loginButton;
class JButton
LoginForm --> JButton:关联
ClassOne -- ClassTwo:关联
'聚合'
class Car
+ Engine engine;
+ Car(Engine engine):void
+ setEngine(Engine engine):void
class Engine
Car o--Engine:聚合
'组合'
class Head
- Mouth mouth;
+ Head();
class Mouth
Head *--Mouth:拥有
'依赖'
class Driver
+ drive(Car car):void
class Car
+ move():void
Driver ..> Car:依赖
@enduml
- 效果图
用例图
- 代码
@startuml
left to right direction
actor 收银员 as a
actor 供应商 as b
actor 顾客 as c
c --> (买饮料)
b --> (放置饮料)
(放置饮料) ..> (打开机器)
(放置饮料) ..> (关闭机器)
a --> (收钱)
(收钱) ..> (打开机器)
(收钱) ..> (关闭机器)
@enduml
- 示例图
对象图
- 代码
@startuml
'https://plantuml.com/object-diagram
object 客户对象
客户对象 -- 订单对象1
客户对象 -- 订单对象2
客户对象 -- 订单对象3
map 订单对象1
Number=12
map 订单对象2
Number=12
map 订单对象3
Number=12
订单对象1 -- 特殊订单1
订单对象2 -- 特殊订单2
订单对象3 -- 特殊订单3
map 特殊订单1
Number=20
map 特殊订单2
Number=30
map 特殊订单3
Number=40
@enduml
- 示例图
活动图
- 代码
@startuml
start
:ClickServlet.handleRequest();
:new page;
if (Page.onSecurityCheck) then (true)
:Page.onInit();
if (isForward?) then (no)
:Process controls;
if (continue processing?) then (no)
stop
endif
if (isPost?) then (yes)
:Page.onPost();
else (no)
:Page.onGet();
endif
:Page.onRender();
endif
else (false)
endif
if (do redirect?) then (yes)
:redirect process;
else
if (do forward?) then (yes)
:Forward request;
else (no)
:Render page template;
endif
endif
stop
@enduml
- 样式
部署图
- 代码
@startuml
header TA项目物理架构图
footer TA项目物理架构图
left to right direction
actor TaUser as taUser
node TaApp as taApp
agent LxSDK as lxsdk
agent TaClient as taClient
folder tiananuser_folder
cloud tiananuserCluster
node tomcat1_tiananuser
node tomcat2_tiananuser
node tomcat3_tiananuser
tiananuserCluster -down-> tomcat1_tiananuser
tiananuserCluster -down-> tomcat2_tiananuser
tiananuserCluster -down-> tomcat3_tiananuser
folder tianansp_folder
cloud tiananspCluster
node tomcat1_tianansp
node tomcat2_tianansp
node tomcat3_tianansp
tiananspCluster -down-> tomcat1_tianansp
tiananspCluster -down-> tomcat2_tianansp
tiananspCluster -down-> tomcat3_tianansp
node nginx as nginx
nginx --> tiananuserCluster:负载均衡/路由
nginx --> tiananspCluster:负载均衡/路由
taUser --> taApp : 访问
taApp --> nginx:http/https
database tiananuser_database[
用户登录数据库
]
database tianansp_database[
运营活动数据库
]
database redis[
redis缓存
]
tiananuser_folder -down-> tiananuser_database
tianansp_folder -right-> tianansp_database
tiananuser_folder -down-> redis
tianansp_folder -up-> redis
node zk [
zookeeper注册中心
dubbo的消费者跟生产者通信中间件
定时任务elasticjob的配置中间件
]
tiananuser_folder -down-> zk
tianansp_folder -up-> zk
node apollo [
apollo配置中心
]
queue kafka[
kafka集群
]
tiananuser_folder -down-> apollo
tianansp_folder -up-> apollo
tiananuser_folder -down-> kafka
tianansp_folder -up-> kafka
file fileCDN [
七牛云或者阿里云存储
]
tiananuser_folder -down-> fileCDN
tianansp_folder -up-> fileCDN
cloud ELK
node elsticSearch
node filebeat
node kibana
node kubernetes
node healmcharts[
交付服务
]
node harbor[
harbor监控管理kubernetes对象
]
tiananuser_folder -down-> ELK:日志写入
tianansp_folder -up-> ELK:日志写入
tiananuser_folder -down-> kubernetes:发布和管控docker节点
tianansp_folder -up-> kubernetes:发布和管控docker节点
@enduml
- 样式
包图
- 代码
@startuml
'https://plantuml.com/component-diagram
package "Some Group"
HTTP - [First Component]
[Another Component]
node "Other Groups"
FTP - [Second Component]
[First Component] --> FTP
cloud
[Example 1]
database "mysql"
folder "This is my folder"
[Folder 3]
frame "Foo"
[Frame 4]
[Another Component] --> [Example 1]
[Example 1] --> [Folder 3]
[Folder 3] --> [Frame 4]
@enduml
- 样式
状态图
- 代码
@startuml
state start1 <<start>>
state choice1 <<choice>>
state fork1 <<fork>>
state join2 <<join>>
state end3 <<end>>
[*] --> choice1 : from start\\nto choice
start1 --> choice1 : from start stereo\\nto choice
choice1 --> fork1 : from choice\\nto fork
choice1 --> join2 : from choice\\nto join
choice1 --> end3 : from choice\\nto end stereo
fork1 ---> State1 : from fork\\nto state
fork1 --> State2 : from fork\\nto state
State2 --> join2 : from state\\nto join
State1 --> [*] : from state\\nto end
join2 --> [*] : from join\\nto end
@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
- 样式
思维导图
- 代码
@startmindmap
'https://plantuml.com/mindmap-diagram
caption figure 1
title My super title
* <&flag>Debian
** <&globe>Ubuntu
*** Linux Mint
*** Kubuntu
*** Lubuntu
*** KDE Neon
** <&graph>LMDE
** <&pulse>SolydXK
** <&people>SteamOS
** <&star>Raspbian with a very long name
*** <s>Raspmbc</s> => OSMC
*** <s>Raspyfi</s> => Volumio
header
My super header
endheader
center footer My super footer
legend right
Short
legend
endlegend
@endmindmap
- 样式
以上是关于# Puml 语法说明的主要内容,如果未能解决你的问题,请参考以下文章