/** * 关注公众号:键捡田螺的小男孩 */ @startuml title Sequence Diagram of User login actor User as user
participant 'gateway' as gateway participant 'user-core' as userCore database 'MySQL' as mysql database 'Redis' as redis
autonumber user-> gateway:login request,param:username,password activate gateway gateway-> userCore:forward the login request activate userCore userCore-> userCore :check the login param userCore-> mysql:query user info from mysql by username activate mysql mysql-> userCore:response with username and password deactivate mysql userCore->userCore:compare the requested password with the DB's password userCore-> userCore: generate an unique token userCore--> redis: save the token to redis userCore-> gateway: response with the token deactivate userCore gateway-> user: login success with the token deactivate gateway @enduml
/** * 关注公众号:键捡田螺的小男孩 */ @startuml title Sequence Diagram of User login actor User as user
participant 'gateway' as gateway participant 'user-core' as userCore database 'MySQL' as mysql database 'Redis' as redis
autonumber user-> gateway:login request,param:username,password activate gateway gateway-> userCore:forward the login request activate userCore userCore-> userCore :check the login param userCore-> mysql:query user info from mysql by username activate mysql mysql-> userCore:response with username and password deactivate mysql userCore->userCore:compare the requested password with the DB's password userCore-> userCore: generate an unique token userCore--> redis: save the token to redis userCore-> gateway: response with the token deactivate userCore gateway-> user: login success with the token deactivate gateway @enduml
Bob -> Alice: 认证失败 group 我自己的标签 Alice -> Log : 开始记录攻击日志 loop 1000次 Alice -> Bob: DNS 攻击 end Alice -> Log : 结束记录攻击日志 end
else 另一种失败
Bob -> Alice: 请重复
end @enduml
对应的时序图如下:
4. 如何用PlantUML 画UML用例图
什么是用例图?
用例图(英语:use case diagram)是用户与系统交互的最简表示形式,展现了用户和与他相关的用例之间的关系。通过用例图,人们可以获知系统不同种类的用户和用例。用例图也经常和其他图表配合使用。
如何用PlantUML画UML用例图呢?
你可以先新建一个PlantUML文件,然后选择user case,并定义个文件名
就会有默认的UML用例图生成啦
我挑官网一个用例图demo来介绍吧,代码如下:
@startuml left to right direction actor Guest as g package Professional { actor Chef 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 } fc --> UC4 g --> UC1 g --> UC2 g --> UC3 @enduml
start :user request login; if (is request param null?) then (N) :query user info by username; if (is user info null ?) then (N) :compare the password; if (Is password right?) then (Y) :generate a token ,and set it to redis; :response with login success; else(N) :response with wrong password code; stop endif else(Y) :response with error userinfo; stop endif else(Y) :response with error param; stop endif stop @enduml