MVC3快速搭建Web应用(一)
<div id="cnblogs_post_body">最近随着项目接近尾声,感觉有必要把自己&rdquo;拼凑&rdquo;的这一套基于asp.net mvc 3的Web应用快速开发模式分享出来。顺便给此项目做个总结。关键词:Razor、easyui、Entityframework、T4 、Linq to Entity、Json
1)Razor:ASP.NET MVC3引入了一个新的View引擎.
2)easyui:基于jquery的一个ui界面框架
3)Entityframework:微软的数据库关系映射框架
4)T4:代码生成的模版语法 。MVC中添加控制器和添加视图对话框执行使用在幕后的 T4 模板的代码生成。
先来几个效果图:
http://pic002.cnblogs.com/images/2012/28631/2012062117353772.jpg
此图中左边的菜单栏是通过数据库配置动态生成,并且与权限挂钩,权限粒度控制到按钮级别,即可指派某个角色是否拥有增加、删除某记录的权限
http://pic002.cnblogs.com/images/2012/28631/2012062117360454.jpg
图中列表的header全部都是通过自动生成完成,设备详细信息页面经由改造mvc3的details生成。
http://pic002.cnblogs.com/images/2012/28631/2012062117435871.png
此编辑界面也是由T4模版自动生成。甚至包括中文label(提取自Powerdesigner中的字段注释),包括下拉列表,日期选择框,都是根据判断数据库类型自动添加。
一、使用PowerDesigner搭建数据模型
在EntityFramework中,有两种开发模式,代码优先(Code First)与普通的先生成数据库然后再开发,本项目采用的是后一种。
个人习惯直接搭建概念模型,需求初步敲定后,为物理模型添加细节,在这个期间,给每个字段添加注释是非常重要的,因为后期你需要根据这些中文注释来生成界面上的文字。本人使用了一个Powerdesigner中的自动修改脚本来将Name转换为Commet
<div class="cnblogs_code">Option ExplicitValidationMode = TrueInteractiveMode = im_BatchDim mdl 'the current model'get the current active modelSet mdl = ActiveModelIf (mdl Is Nothing) ThenMsgBox "There is no current Model"ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) ThenMsgBox "The current model is not an Physical Data model."ElseProcessFolder mdlEnd If'This routine copy name into code for each table, each column and each view'of the current folderPrivate sub ProcessFolder(folder)Dim Tab 'running tablefor each Tab in folder.tablesif not Tab.isShortcut thenif Tab.Comment ="" thenTab.Comment = tab.nameelseTab.comment=Tab.name &"," &Tab.commentEnd ifDim col 'running columnfor each col in tab.columnsif col.comment ="" thencol.comment= col.nameelsecol.comment=col.name & "," &col.commentend ifnextend ifnextDim view 'running viewfor each view in folder.Viewsif not view.isShortcut thenview.comment = view.nameend ifnext'go into the sub-packagesDim f 'running folderFor Each f In folder.Packagesif not f.IsShortcut thenProcessFolder fend ifNextend sub
页:
[1]