实体模型主要实现单表操作(insert, update, delete, select),凡是需要这4条SQL语句要完成的功能,基本上都可以完成。多表处理的,需要用到关系模型,后续专门讲述。
前面写过一篇文章叫“主题切换及其管理”,连接地址为http://my.oschina.net/u/1245989/blog/165402。
里面有详细的模型配置文件,但只是一个结果而已,接下来,对其进行详细剖析,讲述如何进进行配置。
1
2
|
<
entity-model
id
=
"theme"
name
=
"theme"
title
=
"主题"
enable-delete
=
"true"
enable-modity
=
"true"
version
=
"2.0"
cache-enabled
=
"true"
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<
groups
>
<
group
id
=
"basicgroup"
name
=
"basicgroup"
title
=
"基本字段"
enable-delete
=
"true"
enable-modity
=
"true"
>
<
field
standard-field-id
=
"theme_id"
primary
=
"true"
unique
=
"true"
display
=
"false"
not-null
=
"false"
auto-increase
=
"false"
editable
=
"false"
hidden
=
"false"
table-field
=
"true"
id
=
"theme_id"
/>
<
field
standard-field-id
=
"theme_code"
primary
=
"false"
unique
=
"false"
display
=
"false"
not-null
=
"false"
auto-increase
=
"false"
editable
=
"false"
hidden
=
"false"
table-field
=
"true"
id
=
"theme_code"
/>
<
field
standard-field-id
=
"theme_title"
primary
=
"false"
unique
=
"false"
display
=
"false"
not-null
=
"false"
auto-increase
=
"false"
editable
=
"false"
hidden
=
"false"
table-field
=
"true"
id
=
"theme_title"
/>
<
field
standard-field-id
=
"theme_css_path"
primary
=
"false"
unique
=
"false"
display
=
"false"
not-null
=
"false"
auto-increase
=
"false"
editable
=
"false"
hidden
=
"false"
table-field
=
"true"
id
=
"theme_css_path"
/>
<
field
standard-field-id
=
"theme_thumbnail"
primary
=
"false"
unique
=
"false"
display
=
"false"
not-null
=
"false"
auto-increase
=
"false"
editable
=
"false"
hidden
=
"false"
table-field
=
"true"
id
=
"theme_thumbnail"
/>
</
group
>
</
groups
>
|
1
|
table-field="true"
|
定义了其是否是一个表字段,实体模型对象与数据表是一一对应的,但是实体模型中的字段不一定都是建表所有的。
比如:我们要做一个用户管理,其中要做一个修改密码的功能,一般来说,修改密码都有一个重复输入密码的框来进行验证,避免用户打入时不小心输入错误,而无法登录的问题。很显然,我们在做功能的时候是需要有这个域的,但是在数据库表中,是不需要有这么个字段的,因此,可以通过配置其属性table-field="false",来增加这个域,但是以建表的时候,又忽略它。
如此,就可以把模型的字段定义好了。
模型上,有两种类型的操作对象可以配置,一种是操作,一种是视图。
下面逐个进行分析:
首先是新建操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<
operation
id
=
"thememodelopadduuid"
name
=
"addTheme"
title
=
"新增"
enable-delete
=
"true"
enable-modity
=
"true"
type
=
"add"
fixed-size
=
"false"
modal
=
"true"
>
<
operation-group
id
=
"addopbasicgroup"
name
=
"basicgroup"
title
=
"操作字段"
enable-delete
=
"true"
enable-modity
=
"true"
>
<
operation-fields
>
<
operation-field
editable
=
"true"
hidden
=
"false"
field-id
=
"theme_code"
/>
<
operation-field
editable
=
"true"
hidden
=
"false"
field-id
=
"theme_title"
/>
<
operation-field
editable
=
"true"
hidden
=
"false"
field-id
=
"theme_css_path"
>
<
input-mode
type
=
"textWholeLineMode"
></
input-mode
>
</
operation-field
>
<
operation-field
editable
=
"true"
hidden
=
"false"
field-id
=
"theme_thumbnail"
>
<
input-mode
type
=
"textWholeLineMode"
></
input-mode
>
</
operation-field
>
</
operation-fields
>
</
operation-group
>
</
operation
>
|
1
2
3
|
<
operation
id
=
"thememodelopadduuid"
name
=
"addTheme"
title
=
"新增"
enable-delete
=
"true"
enable-modity
=
"true"
type
=
"add"
fixed-size
=
"false"
modal
=
"true"
>
|
type="add",是指这个操作的操作类型是什么,可选的范围在模型类型定义文件中获取,fixed-size表示窗口大小是否允许修改,如果是true,则表示不允许修改,如果是false,则可以修改。modal属性标明了是否是模式窗口,建议所有的操作都采用模式窗口方式。
1
2
|
<
operation-group
id
=
"addopbasicgroup"
name
=
"basicgroup"
title
=
"操作字段"
enable-delete
=
"true"
enable-modity
=
"true"
>
|
display-mode表明分组的显示方式,其值可以为:Tab,FieldSet,Wizard,Expander,Accordion,Carousel等,以控制字段的显示方式,实际上,通过配置display-mode及多层分组可以做出非常漂亮的界面组织形式,强烈建议必须掌握。如果不会用display-mode和operation-group嵌套,做出来的界面只能叫normal,如果会用的话,做出来的界面就是professional,差别是非常大的。
有时,界面中还要引用其它操作或视图的内容,显示在当前操作界面中。此时可以在operation-group节点下添加reference节点来完成:
1
|
<
reference
id
=
""
type
=
"operation|view"
model-id
=
""
/>
|
id为所引用对象的id,type可以有两种选择,operation或view,model-id表示引用的模型的ID,如果是当前模型,则可以忽略。
当然,引用的内容也有可能来自其它页面,这个时候可以用属性url=""的方式进行指定。
好吧,由于我们的主题管理太过简单,所以这些内容都没有用到,先跳过之。
1
2
|
<
operation-field
editable
=
"true"
hidden
=
"false"
field-id
=
"theme_code"
/>
|
指操作时用的字段,它只能从group中的field中进行引用。editable="true" 表示是否可编辑,hidden="false"表示是否隐藏。在它下面可以添加子节点input-mode,可以用来指定各种输入模式,如果不指定则表示用标准的文本输入框模式
1
|
<
input-mode
type
=
"textWholeLineMode"
></
input-mode
>
|
对于添加操作来说,没有查询字段,对于修改和删除字段,则需要添加查询字段,一般来说是主键,如果不配置查询字段,后续会非常严重!会导致全表删除或修改。
在修改及删除中就存在查询字段,来控制修改的范围。
1
2
3
4
|
<
condition-fields
>
<
condition-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_id"
connect-mode
=
"AND"
/>
</
condition-fields
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<
view
id
=
"thememodeloptableuuid"
name
=
"tabletheme"
title
=
"主题管理"
enable-delete
=
"true"
enable-modity
=
"true"
type
=
"table"
page-size
=
"10"
allow-edit
=
"false"
allow-filter-front
=
"false"
fixed-size
=
"false"
modal
=
"false"
front-paging
=
"false"
>
<
view-groups
>
<
view-group
id
=
"viewbasicgroup"
name
=
"basicgroup"
title
=
"基本信息"
enable-delete
=
"true"
enable-modity
=
"true"
>
<
display-field
editable
=
"false"
hidden
=
"true"
field-id
=
"theme_id"
aggregate-by-view
=
"false"
/>
<
display-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_code"
aggregate-by-view
=
"false"
/>
<
display-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_title"
aggregate-by-view
=
"false"
/>
</
view-group
>
</
view-groups
>
<
references
>
<
operation-reference
type
=
"operation"
id
=
"thememodelopadduuid"
/>
<
operation-reference
type
=
"operation"
id
=
"thememodelopaddcopyuuid"
/>
<
operation-reference
type
=
"operation"
id
=
"thememodelopdeleteuuid"
/>
<
operation-reference
type
=
"operation"
id
=
"thememodelopupdateuuid"
/>
<
operation-reference
type
=
"operation"
id
=
"thememodelopqueryuuid"
/>
</
references
>
</
view
>
|
1
2
3
4
|
<
view
id
=
"thememodeloptableuuid"
name
=
"tabletheme"
title
=
"主题管理"
enable-delete
=
"true"
enable-modity
=
"true"
type
=
"table"
page-size
=
"10"
allow-edit
=
"false"
allow-filter-front
=
"false"
fixed-size
=
"false"
modal
=
"false"
front-paging
=
"false"
>
|
View-groups中可以有多个group,如果有多个group,支持二层表头模式,大致如下:
1
2
3
4
5
6
7
8
9
10
11
|
<
view-groups
>
<
view-group
id
=
"viewbasicgroup"
name
=
"basicgroup"
title
=
"基本信息"
enable-delete
=
"true"
enable-modity
=
"true"
>
<
display-field
editable
=
"false"
hidden
=
"true"
field-id
=
"theme_id"
aggregate-by-view
=
"false"
/>
<
display-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_code"
aggregate-by-view
=
"false"
/>
<
display-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_title"
aggregate-by-view
=
"false"
/>
</
view-group
>
</
view-groups
>
|
下面是引用的操作,引用了操作或视图后,可以在操作列表中显示相关的按钮,以便于进行相应的操作。
1
2
3
4
5
6
7
8
9
10
11
|
<
references
>
<
operation-reference
type
=
"operation"
id
=
"thememodelopadduuid"
/>
<
operation-reference
type
=
"operation"
id
=
"thememodelopaddcopyuuid"
/>
<
operation-reference
type
=
"operation"
id
=
"thememodelopdeleteuuid"
/>
<
operation-reference
type
=
"operation"
id
=
"thememodelopupdateuuid"
/>
<
operation-reference
type
=
"operation"
id
=
"thememodelopqueryuuid"
/>
</
references
>
|
上面就引用了添加,修改删除,复制添加等操作。具体如下图所示:
下面是选择并修改主题的视图:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<
view
id
=
"thememodelopcarduuid"
name
=
"cardtheme"
title
=
"主题选择"
enable-delete
=
"true"
enable-modity
=
"true"
type
=
"card"
page-size
=
"0"
allow-edit
=
"false"
allow-filter-front
=
"true"
fixed-size
=
"false"
modal
=
"false"
front-paging
=
"false"
>
<
customize-stage-configs
>
<
customize-stage-config
stage-name
=
"card"
view-path
=
"/biz/theme/theme_card.page"
>
</
customize-stage-config
>
</
customize-stage-configs
>
<
condition-fields
>
</
condition-fields
>
<
view-groups
>
<
view-group
id
=
"viewbasicgroup"
name
=
"basicgroup"
title
=
"基本信息"
enable-delete
=
"true"
enable-modity
=
"true"
>
<
display-field
editable
=
"false"
hidden
=
"true"
field-id
=
"theme_id"
aggregate-by-view
=
"false"
/>
<
display-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_code"
aggregate-by-view
=
"false"
/>
<
display-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_title"
aggregate-by-view
=
"false"
/>
<
display-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_css_path"
aggregate-by-view
=
"false"
/>
<
display-field
editable
=
"false"
hidden
=
"false"
field-id
=
"theme_thumbnail"
aggregate-by-view
=
"false"
/>
</
view-group
>
</
view-groups
>
</
view
>
|
由于其渲染方式比较特殊,因此采用下面的配置来修改渲染模板为自定义模板:
1
2
3
4
5
|
<
customize-stage-configs
>
<
customize-stage-config
stage-name
=
"card"
view-path
=
"/biz/theme/theme_card.page"
>
</
customize-stage-config
>
</
customize-stage-configs
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#@wijDialog("${modelDefine.id}_${operationDefine.id}" "${operationDefine.title}" "" $option $captionButtons)
#foreach($bean in $modelProcessResult.beans)
<
a
href
=
"javascript:doChangeTheme('${TINY_CONTEXT_PATH}$bean.themeCssPath')"
><
img
title
=
"$bean.themeTitle"
style
=
"float:left;border:1px solid;margin:5px 5px;width:50pt;"
src
=
"${TINY_CONTEXT_PATH}$bean.themeThumbnail"
/></
a
>
#end
#end##dialog
<
script
>
function doChangeTheme(path){
var list=$("link");
for(var i=0;i<
list.length
;i++){
var
link
=
list
.get(i);
var
pos
=
link
.href.indexOf("/themes/");
if(pos>0){
pos=link.href.indexOf(contextPath+"/");
link.href=link.href.substr(0,pos)+ path;
}
}
}
</
script
>
|
就产生了下面的窗口:
因此,只需要通过简单的配置就可以生成非常漂亮的界面。实际上,还支持数据校验等功能,上面没有演示。
只要在group下的field节点下,增加下面的节点即可:
1
2
3
4
|
<
validate-rules
>
<
validate-rule
rule-name
=
"required"
/>
<
validate-rule
rule-name
=
"max"
rule-value
=
"30"
/>
</
validate-rules
>
|
如果被使用者禁用了前台校验,直接向后台提交数据,还会进行一次后台数据校验,确保数据的合法有效。
当然,上面的文章还只是简明扼要的讲一下,详细参见开发手册。