7eb729c48830f0901953bb137666ecefd329d0ed
\345\275\223\345\211\215SDK\347\211\210\346\234\254\344\270\215\346\224\257\346\214\201\350\277\234\347\250\213\350\260\203\347\224\250\357\274\214\350\257\267\345\215\207\347\272\247SDK\345\206\215\345\260\235\350\257\225!.md
... | ... | @@ -0,0 +1,158 @@ |
1 | +# 1.ManyToOne功能增强 |
|
2 | + |
|
3 | + |
|
4 | +## 1.ManyToOne不需要填写依赖和允许跨App安装 |
|
5 | +1. 如果是模型的ManyToOne依赖,app.json不需要填写应用依赖 |
|
6 | +2. 如果2个APP不存在继承扩展,只存在调用关系或者模型的many2one引用,可以不安装在一起 |
|
7 | +3. **注意:如果模型之前存在继承扩展关系,必须安装在一起** |
|
8 | + |
|
9 | +1.@ManyToOne 指定targetModel的格式为 appName.modelName |
|
10 | +```java |
|
11 | +@Model |
|
12 | +public class TestLog extends BaseModel { |
|
13 | + |
|
14 | + @ManyToOne(targetModel = "newSdkApp.TestOrg")// Many2one跨app安装,格式为:其他app的名字.模型名 |
|
15 | + @JoinColumn(name = "org_code") |
|
16 | + private Map<String, Object> testOrg; |
|
17 | + |
|
18 | +} |
|
19 | +``` |
|
20 | + |
|
21 | +2.如果需要再ManyToOne方添加tab页显示另外一个app的数据,需要再tabs的body里面指定 "app": "newSdkAppOthers" |
|
22 | + |
|
23 | +```json |
|
24 | +"tabs": [ |
|
25 | + { |
|
26 | + "body": { |
|
27 | + "columns": [ |
|
28 | + { |
|
29 | + "label": "备注", |
|
30 | + "name": "remark" |
|
31 | + }, |
|
32 | + { |
|
33 | + "label": "创建时间", |
|
34 | + "name": "createDate" |
|
35 | + } |
|
36 | + ], |
|
37 | + "app": "newSdkAppOthers", |
|
38 | + "field": "testLogs", |
|
39 | + "type": "grid" |
|
40 | + }, |
|
41 | + "header": "日志列表", |
|
42 | + "tbar": [] |
|
43 | + } |
|
44 | +] |
|
45 | +``` |
|
46 | + |
|
47 | +## 2.ManyToOne指定任意的显示字段 |
|
48 | + |
|
49 | +之前的ManyToOne默认只能是 displayForModel字段,现在已经修改成支持任意字段的显示 |
|
50 | + |
|
51 | +**通过注解displayFormat指定任意显示的字段(指定的字段必须是存在数据库中的,不能是related字段):** |
|
52 | + |
|
53 | +**指定任意字段:** |
|
54 | + |
|
55 | +```java |
|
56 | +@ManyToOne(displayName = "2单选异步获取Many2one", cascade = {CascadeType.DEL_SET_NULL},displayFormat ="orgCode") |
|
57 | +@ManyToOne(displayName = "2单选异步获取Many2one", cascade = {CascadeType.DEL_SET_NULL},displayFormat ="${orgCode}") |
|
58 | +``` |
|
59 | + |
|
60 | + |
|
61 | +**指定多个字段格式化输出:** |
|
62 | +```java |
|
63 | +@ManyToOne(displayName = "2单选异步获取Many2one", cascade = {CascadeType.DEL_SET_NULL},displayFormat ="${name}-${orgCode}") |
|
64 | +``` |
|
65 | + |
|
66 | + |
|
67 | +## 3.ManyToOne关联非ID字段,比如关联code字段 |
|
68 | + |
|
69 | +之前的ManyToOne默认只能是关联ID字段,现在可以关联code等非ID字段 |
|
70 | +示例 |
|
71 | + |
|
72 | +**通过注解referencedProperty指定任意字段:** |
|
73 | + |
|
74 | +```java |
|
75 | + @ManyToOne(displayName = "2单选异步获取Many2one", cascade = {CascadeType.DEL_SET_NULL}) |
|
76 | + @JoinColumn(name = "org_id", referencedProperty = "orgCode") |
|
77 | + private TestOrg org; |
|
78 | + |
|
79 | + //引擎内置的base app的模型可以不指定app |
|
80 | + @ManyToOne(displayName = "组织", targetModel = "rbac_organization") |
|
81 | + @JoinColumn(name = "org_code", referencedProperty = "code") |
|
82 | + private Map<String, Object> organization; |
|
83 | + |
|
84 | + //如果明确知道是跨app安装,需要指定app.modelname, |
|
85 | + @ManyToOne(displayName = "组织", targetModel = "mbm-main.res_enterprise") |
|
86 | + @JoinColumn(name = "org_code", referencedProperty = "code") |
|
87 | + private Map<String, Object> enterprise; |
|
88 | + |
|
89 | +``` |
|
90 | + |
|
91 | +## 4.ManyToOne和ManyToMany支持related属性显示 |
|
92 | + |
|
93 | + |
|
94 | +```java |
|
95 | + 4.1.Many2one的用法 ,不需要使用select属性 |
|
96 | + |
|
97 | + |
|
98 | +@@Model(name = "TestUser", description = "用户") |
|
99 | +public class TestUser extends BaseModel<TestUser> { |
|
100 | + @ManyToOne(displayName = "组织") |
|
101 | + @JoinColumn(name = "org_id", referencedProperty = "id") |
|
102 | + private TestOrg org; |
|
103 | + |
|
104 | +} |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | +@Model(name = "TestOrg", description = "组织") |
|
109 | +public class TestOrg extends BaseModel<TestOrg> { |
|
110 | + |
|
111 | + @Property(displayName = "名称") |
|
112 | + private String name; |
|
113 | + |
|
114 | + @ManyToOne |
|
115 | + @JoinColumn(name = "parent_id") |
|
116 | + private TestOrg parent; |
|
117 | + |
|
118 | + |
|
119 | + @Property(displayName = "父组织",related = "parent.name",displayForModel = true) |
|
120 | + private String parentName; |
|
121 | +} |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | +4.2.ManyToMany |
|
129 | + |
|
130 | + @ManyToMany |
|
131 | + @JoinTable(name = "role_user", joinColumns = @JoinColumn(name = "user_id", nullable = false), |
|
132 | + inverseJoinColumns = @JoinColumn(name = "role_id", nullable = false)) |
|
133 | + @Selection(multiple = true,properties = "parentNmae") |
|
134 | + @Property(displayName = "角色") |
|
135 | + private List<TestRole> roleList; |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | +@Model |
|
140 | +public class TestRole extends BaseModel { |
|
141 | + |
|
142 | + @Property(columnName = "role_name", displayName = "角色名称") |
|
143 | + private String roleName; |
|
144 | + |
|
145 | + |
|
146 | + @ManyToOne |
|
147 | + @JoinColumn(name = "parent_id") |
|
148 | + private TestOrg parent; |
|
149 | + |
|
150 | + |
|
151 | + @Property(displayName = "父组织",related = "parent.name") |
|
152 | + private String parentNmae; |
|
153 | + |
|
154 | + } |
|
155 | + |
|
156 | +``` |
|
157 | + |
|
158 | + |