0e54782d9b2f60f49dfe669288c3dbc964a487d9
Many2One\350\267\250App\345\256\211\350\243\205.md
... | ... | @@ -89,5 +89,94 @@ public class TestLog extends BaseModel { |
89 | 89 | |
90 | 90 | ``` |
91 | 91 | |
92 | +## 3.ManyToOne关联非ID字段,比如关联code字段 |
|
93 | + |
|
94 | +之前的ManyToOne默认只能是关联ID字段,现在可以关联code等非ID字段 |
|
95 | +示例 |
|
92 | 96 | |
97 | +**通过注解referencedProperty指定任意字段:** |
|
98 | + |
|
99 | +```java |
|
100 | + @ManyToOne(displayName = "2单选异步获取Many2one", cascade = {CascadeType.DEL_SET_NULL}) |
|
101 | + @JoinColumn(name = "org_id", referencedProperty = "orgCode") |
|
102 | + private TestOrg org; |
|
103 | + |
|
104 | + //引擎内置的base app的模型可以不指定app |
|
105 | + @ManyToOne(displayName = "组织", targetModel = "rbac_organization") |
|
106 | + @JoinColumn(name = "org_code", referencedProperty = "code") |
|
107 | + private Map<String, Object> organization; |
|
108 | + |
|
109 | + //如果明确知道是跨app安装,需要指定app.modelname, |
|
110 | + @ManyToOne(displayName = "组织", targetModel = "mbm-main.res_enterprise") |
|
111 | + @JoinColumn(name = "org_code", referencedProperty = "code") |
|
112 | + private Map<String, Object> enterprise; |
|
113 | + |
|
114 | +``` |
|
115 | + |
|
116 | +## 4.ManyToOne和ManyToMany支持related属性显示 |
|
117 | + |
|
118 | + |
|
119 | +```java |
|
120 | + 1.Many2one的用法 ,不需要使用select属性 |
|
121 | + |
|
122 | + |
|
123 | +@@Model(name = "TestUser", description = "用户") |
|
124 | +public class TestUser extends BaseModel<TestUser> { |
|
125 | + @ManyToOne(displayName = "组织") |
|
126 | + @JoinColumn(name = "org_id", referencedProperty = "id") |
|
127 | + private TestOrg org; |
|
128 | + |
|
129 | +} |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | +@Model(name = "TestOrg", description = "组织") |
|
134 | +public class TestOrg extends BaseModel<TestOrg> { |
|
135 | + |
|
136 | + @Property(displayName = "名称") |
|
137 | + private String name; |
|
138 | + |
|
139 | + @ManyToOne |
|
140 | + @JoinColumn(name = "parent_id") |
|
141 | + private TestOrg parent; |
|
142 | + |
|
143 | + |
|
144 | + @Property(displayName = "父组织",related = "parent.name",displayForModel = true) |
|
145 | + private String parentName; |
|
146 | +} |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | +2.ManyToMany |
|
154 | + |
|
155 | + @ManyToMany |
|
156 | + @JoinTable(name = "role_user", joinColumns = @JoinColumn(name = "user_id", nullable = false), |
|
157 | + inverseJoinColumns = @JoinColumn(name = "role_id", nullable = false)) |
|
158 | + @Selection(multiple = true,properties = "parentNmae") |
|
159 | + @Property(displayName = "角色") |
|
160 | + private List<TestRole> roleList; |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | +@Model |
|
165 | +public class TestRole extends BaseModel { |
|
166 | + |
|
167 | + @Property(columnName = "role_name", displayName = "角色名称") |
|
168 | + private String roleName; |
|
169 | + |
|
170 | + |
|
171 | + @ManyToOne |
|
172 | + @JoinColumn(name = "parent_id") |
|
173 | + private TestOrg parent; |
|
174 | + |
|
175 | + |
|
176 | + @Property(displayName = "父组织",related = "parent.name") |
|
177 | + private String parentNmae; |
|
178 | + |
|
179 | + } |
|
180 | + |
|
181 | +``` |
|
93 | 182 |