Boost Your Documentation Efficiency: Master PlantUML for Rapid Diagram Creation
This article introduces PlantUML, an open‑source tool that lets developers generate various UML diagrams directly from text, explains how to install the IntelliJ IDEA plugin, and provides step‑by‑step code examples for sequence, use‑case, class, activity, and mind‑map diagrams, complete with visual outputs.
PlantUML Introduction
PlantUML is an open‑source UML diagram tool that generates graphics from plain text, supporting sequence, class, object, activity, mind‑map and other diagram types.
Installation
Install the PlantUML plugin in IntelliJ IDEA via the plugin marketplace.
Search for
PlantUMLand install the top‑ranked plugin.
If the network is poor, click the
Plugin homepagebutton to download the zip package manually.
After download, install from the local file.
Usage
Use the plugin to draw sequence, use‑case, class, activity and mind‑map diagrams.
Sequence Diagram
Example: Oauth2 authorization‑code flow diagram.
<code>@startuml
title Oauth2令牌颁发之授权码模式
actor User as user
participant "User Agent" as userAgent
participant "Client" as client
participant "Auth Login" as login
participant "Auth Server" as server
autonumber
user->userAgent:访问客户端
activate userAgent
userAgent->login:重定向到授权页面+clientId+redirectUrl
activate login
login->server:用户名+密码+clientId+redirectUrl
activate server
server-->login:返回授权码
login-->userAgent:重定向到redirectUrl+授权码code
deactivate login
userAgent->client:使用授权码code换取令牌
activate client
client->server:授权码code+clientId+clientSecret
server-->client:颁发访问令牌accessToken+refreshToken
deactivate server
client-->userAgent:返回访问和刷新令牌
deactivate client
userAgent-->user:令牌颁发完成
deactivate userAgent
@enduml</code>Key points:
titlesets diagram title;
actordefines a human participant;
participantdefines other participants;
asgives aliases; arrows (
->,
-->) draw relationships;
:adds notes;
autonumberadds sequence numbers;
activate/
deactivatecontrol lifelines.
Use‑Case Diagram
Illustrates relationships between actors (Guest, Chief, Food Critic) and use‑cases (Eat Food, Pay For Food, Drink, Review).
<code>@startuml
left to right direction
actor Guest as g
package Professional {
actor Chief as c
actor "Food Critic" as fc
}
package Restaurant {
usecase "Eat Food" as uc1
usecase "Pay For Food" as uc2
usecase "Drink" as uc3
usecase "Review" as uc4
}
g--> uc1
g--> uc2
g--> uc3
fc--> uc4
@enduml</code>Key points:
left to right directionchanges layout;
packagegroups elements;
actordefines users;
usecasedefines actions;
-->draws relationships.
Class Diagram
Shows static structure of classes Person, Student, Teacher with attributes, methods and inheritance.
<code>@startuml
class Person {
# String name
# Integer age
+ void move()
+ void say()
}
class Student {
- String studentNo
+ void study()
}
class Teacher {
- String teacherNo
+ void teach()
}
Person <|-- Student
Person <|-- Teacher
@enduml</code>Key points:
classdefines a class; visibility symbols
#(protected),
-(private),
+(public);
<|--denotes inheritance.
Activity Diagram
Depicts the order‑confirmation process in an e‑commerce shopping cart.
<code>@startuml
title 生成确认单流程
start
:获取购物车信息并计算好优惠;
:从ums_member_receive_address表中\n获取会员收货地址列表;
:获取该会员所有优惠券信息;
switch(根据use_type判断每个优惠券是否可用)
case(0)
:全场通用;
if (判断所有商品总金额是否\n满足使用起点金额) then (否)
:得到用户不可用优惠券列表;
stop
endif
case(-1)
:指定分类;
if (判断指定分类商品总金额\n是否满足使用起点金额) then (否)
:得到用户不可用优惠券列表;
stop
endif
case(-2)
:判断指定商品总金额是否满足使用起点金额;
if (判断指定分类商品总金额\n是否满足使用起点金额) then (否)
:得到用户不可用优惠券列表;
stop
endif
endswitch
:得到用户可用优惠券列表;
:获取用户积分;
:获取积分使用规则;
:计算总金额,活动优惠,应付金额;
stop
@enduml</code>Key points:
startand
stopmark flow boundaries;
:defines activity nodes;
if … then … elseand
switch … case … endswitchhandle conditional logic;
whileloops are also supported.
Mind‑Map
Shows a hierarchical learning roadmap for the “mall” project, with colored nodes and grouped sections.
<code>@startmindmap
+[#17ADF1] mall学习路线
++[#lightgreen] 推荐资料
++[#lightblue] 后端技术栈
+++_ 项目框架
+++_ 数据存储
+++_ 运维部署
+++_ 其他
++[#orange] 搭建项目骨架
++[#1DBAAF] 项目部署
+++_ Windows下的部署
+++_ Linux下使用Docker部署
+++_ Linux下使用Docker Compose部署
+++_ Linux下使用Jenkins自动化部署
--[#1DBAAF] 电商业务
---_ 权限管理模块
---_ 商品模块
---_ 订单模块
---_ 营销模块
--[#orange] 技术要点
--[#lightblue] 前端技术栈
--[#lightgreen] 进阶微服务
---_ Spring Cloud技术栈
---_ 项目部署
---_ 技术要点
--[#yellow] 开发工具
--[#lightgrey] 扩展学习
@endmindmap</code>Key points:
+and
-create nodes with direction;
[#color]sets node border color;
_removes node border.
Summary
Although many graphical UML tools exist, programmers can achieve higher efficiency by writing diagram definitions as code, especially when integrated with IntelliJ IDEA. Give PlantUML a try for fast, code‑driven diagram creation.
References
Official documentation: https://plantuml.com/zh/
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.