当前位置: 首页 > article >正文

PlantUML 总结

PlantUML 总结

1. 概述

PlantUML 是一个开源工具,允许用户通过简单的文本描述来生成各种UML图表。它支持多种图表类型,包括但不限于序列图、用例图、类图、活动图等。

2. 基本概念

2.1 开始和结束标记
  • @startuml@enduml:用于标记PlantUML代码块的开始和结束。
@startuml
...
@enduml
2.2 标题
  • title:为图表添加标题。
title My First PlantUML Activity Diagram

3. 活动图的基本元素

3.1 开始与结束
  • startstop:表示流程的开始和结束。
start
:Begin Process;
stop
3.2 动作(Action)
  • :ActionName;:表示一个具体的操作或步骤。
start
:Initialize System;
stop
3.3 条件分支
  • if (condition) then (yes)else:用于条件判断。
start
if (Is Valid Input?) then (yes)
    :Process Data;
else (no)
    :Log Error;
endif
stop
3.4 循环
  • while (condition)endwhile:用于循环操作。
start
while (More Data to Process?)
    :Fetch Data;
endwhile
stop
3.5 并发处理
  • forkend fork:用于表示并发执行的操作。
start
fork
    :Task A;
fork again
    :Task B;
end fork
stop

4. 高级用法

4.1 分区(Partition)
  • partition "Name":用于将流程分组,便于组织和可视化。
partition "Data Processing" #LightBlue {
    :Fetch Data;
    :Process Data;
}
4.2 注释
  • note leftnote right:用于在图表中添加注释。
start
:Initialize System;
note right: This is the initialization step.
stop
4.3 参与者(Actor)
  • actor ActorName:用于表示系统外部的人或实体。
actor User
participant "Web Browser" as WB
participant "Server" as S

User -> WB: Open Home Page
WB -> S: Request Home Page
S -> WB: Return Home Page Content
WB -> User: Show Home Page
4.4 返回箭头
  • 在序列图中,可以明确显示返回值。
actor User
participant "Web Browser" as WB
participant "Server" as S

User -> WB: Login Request
activate WB
WB -> S: Forward Login Request
activate S
S -> WB: Authentication Result
return Authenticated Successfully
deactivate S
WB -> User: Display Dashboard
deactivate WB

5. 示例

5.1 简单流程图
@startuml
title Simple Process Example

start

partition "Process A" #LightBlue {
    :Step 1;
    if (Condition?) then (yes)
        :Step 2;
    else (no)
        :Step 3;
    endif
}

partition "Process B" #LightGreen {
    fork
        :Step 4;
    fork again
        :Step 5;
    end fork
}

stop

@enduml
5.2 包含异常处理的流程图
@startuml
title Exception Handling Example

start
:Start Process;
if (Is Valid Input?) then (yes)
    :Process Data;
else (no)
    :Log Error;
    stop
endif
:Finish Process;
stop

@enduml
5.3 复杂条件分支和循环
@startuml
title Complex Conditions and Loops

start
while (More Data to Process?)
    :Fetch Data;
    if (Data Valid?) then (yes)
        :Process Data;
    else (no)
        :Log Error;
    endif
endwhile
:Finalize Processing;
stop

@enduml

6. 自定义皮肤参数

你可以通过设置皮肤参数来自定义图表的外观。

@startuml
skinparam monochrome true
skinparam backgroundColor #EEEBDC
skinparam sequence {
    ArrowColor DeepSkyBlue
    ActorBorderColor DeepSkyBlue
    LifeLineBorderColor blue
    LifeLineBackgroundColor #A9DCDF
}

actor User
participant "Web Browser" as WB
participant "Server" as S

User -> WB: Login Request
activate WB
WB -> S: Forward Login Request
activate S
S -> WB: Authentication Result
return Authenticated Successfully
deactivate S
WB -> User: Display Dashboard
deactivate WB
@enduml

7. 更多图表类型

除了活动图,PlantUML还支持其他多种图表类型,如用例图、类图、时序图等。

7.1 用例图
@startuml
actor User
actor Admin

usecase UC1 as "Login"
usecase UC2 as "Register"
usecase UC3 as "Manage Users"

User --> UC1
Admin --> UC1
Admin --> UC2
Admin --> UC3
@enduml
7.2 类图
@startuml
class Animal {
    +name: String
    +age: int
    +eat()
}

class Dog {
    +bark()
}

Animal <|-- Dog
@enduml
7.3 时序图
@startuml
actor User
participant "Web Browser" as WB
participant "Server" as S

User -> WB: Login Request
activate WB
WB -> S: Forward Login Request
activate S
S -> WB: Authentication Result
return Authenticated Successfully
deactivate S
WB -> User: Display Dashboard
deactivate WB
@enduml

http://www.kler.cn/a/543792.html

相关文章:

  • CCFCSP第34次认证第一题——矩阵重塑(其一)
  • TongETLV3.0安装指引(by lqw)
  • java韩顺平最新教程,Java工程师进阶
  • 在Mac arm架构终端中运行 corepack enable yarn 命令,安装yarn
  • Mac上搭建宝塔环境并部署PHP项目
  • deepseek和chatgpt对比
  • 使用 EDOT 监测由 OpenAI 提供支持的 Python、Node.js 和 Java 应用程序
  • Ubuntu 上安装 Elasticsearch 7.6.0
  • ubuntu22.04可视化界面
  • 如何在Excel和WPS中进行翻译
  • Java 后端开发工程师进阶路线
  • Android10 音频参数导出合并
  • 机器学习核心算法解析
  • QT 5.15.2 开发地图ArcGIS 100.15.6(ArcGIS Runtime SDK for Qt)
  • Java8新特性Optional,Function,Supplier,Consumer
  • 【Cocos TypeScript 零基础 15.1】
  • Jenkins 部署 之 Mac 一
  • ASP.NET Core SignalR实践指南
  • 如何在Java EE中使用标签库?
  • 【实战指南】使用OpenVINO C# API轻松部署飞桨PP-OCRv4模型
  • 讲解ES6中的变量和对象的解构赋值
  • C++ STL容器之set使用及复现
  • 【Go】01输入输出
  • WPF正则表达式验证输入是否包含中文字母数字,不能是纯符号
  • 基于 SpringBoot的流浪宠物管理系统【免费送】
  • chrome-mojo 概述