PlantUml-程序员的画图利器

PlantUml-程序员的画图利器

1. PlantUml简介

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

  • 时序图
  • 用例图
  • 类图
  • 活动图(这是传统语法)
  • 组件图
  • 状态图
  • 对象图
  • 部署图
  • 计时图

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

  • JSON数据
  • 线框图形界面
  • Archimate图
  • 规范和描述语言(SDL)
  • Ditaa图
  • 甘特图
  • 构思图
  • 工作分解结构图
  • 数学与AsciiMath或JLaTeXMath符号
  • 实体关系图

2. 案例图

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

2.1 时序图

@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
@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 用例图

@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
@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 类图

@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
@startuml
abstract Abstract
annotation Annotation
class ClassB
enum enum
interface interface
class ClassA {
    {static} String id
    --
    - List 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 活动图

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

你可能感兴趣的:(其他,plantuml,markdown)