@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 文件,然后选择用户案例,并定义一个文件名。
有默认的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