You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PlantUML中创建带菱形、基数标注的上下文实体关系图?

在PlantUML中实现目标上下文实体关系图的方案

1. 模拟菱形关联符号

PlantUML原生没有内置菱形符号,但可以通过两种方式模拟:

  • 用透明矩形配合特殊字符:利用菱形字符◇,结合透明背景的矩形实现关联节点
@startuml
skinparam rectangle {
    backgroundColor transparent
    borderColor transparent
}
rectangle "◇" as Assoc
rectangle "用户" as User
ellipse "权限" as Permission
User --> Assoc : 拥有
Assoc --> Permission : N
@enduml
  • 用带样式的note定位:如果需要更灵活的位置控制,可使用note模拟
@startuml
rectangle "订单" as Order
ellipse "商品" as Product
note "<size:14>◇</size>" as Assoc at 20,0
Order --> Assoc
Assoc --> Product
@enduml

2. 标注数字+字母(N)的基数

PlantUML支持直接在连接线上自定义基数文本,无需依赖内置语法,直接写在箭头后即可:

@startuml
rectangle "部门" as Dept
ellipse "员工" as Emp
Dept --> Emp : 1,N
rectangle "客户" as Customer
ellipse "合同" as Contract
Customer --> Contract : 1..N
@enduml

如果需要将基数分别放在连接两端,可使用note定位:

@startuml
rectangle "仓库" as Warehouse
ellipse "货物" as Goods
Warehouse --> Goods
note left of Warehouse: 1
note right of Goods: N
@enduml

3. 多线连接椭圆与矩形

实现多线连接有两种便捷方式:

  • 指定锚点连接:利用实体的方位锚点(如neast、seast、nwest、swest)区分多条连接线
@startuml
rectangle "系统核心" as Core
ellipse "外部接口" as API
Core.neast --> API.nwest : 同步调用
Core.seast --> API.swwest : 异步通知
@enduml
  • 隐藏节点辅助:通过无样式的隐藏节点分隔多条连接线,避免线条重叠
@startuml
rectangle "服务A" as ServiceA
ellipse "服务B" as ServiceB
node "" as H1 #hidden
node "" as H2 #hidden
ServiceA --> H1 --> ServiceB : 请求数据
ServiceA --> H2 --> ServiceB : 返回结果
@enduml

内容的提问来源于stack exchange,提问作者Kevin A.S.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 12:10:01