0%

PlantUml-程序员的画图利器

PlantUml-程序员的画图利器

1. PlantUml简介

PlantUML是一个组可以用来在markdown文件中快速生成UML工程图的组件,比如:

除此之外,还支持下面这些非UML图的展示:

2. 案例图

下面给出几个常用的图形为例,至于语法和剩余图形画法可详见官方文档说明。

2.1 时序图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@startuml
actor user
participant client
participant server
database database as db #gray

user -> client :
client -> server : request
alt validate fail case
client <-- server : validate fail !
else
server -[#blue]> db : crud
server <-[#blue]- db
note right
notes
end note
server -> server : deal data
client <-- server :response
client --> user : tips
end
@enduml

2.2 用例图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@startuml
actor user as user
rectangle usecase {
usecase login as uc1
usecase logout as uc2
usecase "query user info" as uc3
usecase "view info" as uc3
usecase (guest view) as uc4
uc3 <|-- uc4
}
package guest {
actor guest1 as guest1
actor guest2 as guest2
}
user <|-- guest1
user <|-- guest2

left to right direction
user --> uc1: operate
user --> uc2
user --> uc3
guest1 --> uc4
guest2 --> uc4
@enduml

2.3 类图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@startuml
abstract Abstract
annotation Annotation
class ClassB
enum enum
interface interface
class ClassA {
{static} String id
--
- List<ClassB> classBList
==
# enum enum
~ interface interface
.. method ..
+ void init()
+ {abstract} void method()
.. setter ..
+ void set()
}
note right of ClassA::method
This member is notes for method or field
end note

Abstract <|-- ClassA
ClassA o--ClassB
ClassA *-- enum
@enduml

2.4 活动图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@startuml
start
partition patition {
:this node1;
:this node2;
}
if(condition) then (yes)
#white: yes node;
else (no)
#gray: no node;
endif
repeat: description
: process;
: process..;
repeat while(more?) is (yes)
->no;
while (while description)
: ...;
endwhile
stop
@enduml
`