转载CSDN (MVC WebAPI 三层分布式框架开发)
前言:SOA(面向服务的架构)是目前企业应用开发过程中普遍采用的技术,基于MVC WebAPI三层分布式框架开发,以此适用于企业信息系统的业务处理,是本文论述的重点。此外,插件技术的应用,富客户端JQuery实现技术,本文也对其具体实现做以说明。相关示例解决方案可以参考GitHub资源,在文章结尾给出。
1. 系统分层体系架构设计
分布式三层系统简单分为数据访问层,业务逻辑层和前端展现层。分层架构设计是构建大型分布式系统的必要手段,因为可以使得系统健壮,可扩展。
SOA即面向服务的架构,可以帮助企业构建灵活,扩展性强的复杂业务系统,按照服务的理念进行功能交付,调用方也不用去知道实现一方的具体细节;双方是按照统一消息格式,接口方式进行交互的。
SOA的实现是基于以Web服务的方式发布Api接口,目前WebAPI是一种Restfule形式的Web服务,相比WCF的复杂性,WebAPI的开发效率更高,而且在配置时也不需要客户端和服务端的xml配置。
企业核心业务数据可以让桌面、Web、平板、手机或物联设备访问,所以需要统一API接口,WebApi作为业务逻辑处理服务能够满足接口访问和接口之间交互的需求。
7,Dapper语法十分简单。并且无须迁就数据库的设计。
读取500条记录,并做简单对象的序列化操作时间对比如下图:
2.2 DataRepository类
2.4 服务实现类
API Controller:
--[HttpGet]
--[HttpPost]
--[HttpPut]
--[HttpDelete]
3.1 Asp.NETMVC 富客户端开发
- /***
- * HttpGet获取服务端数据
- * @url 业务数据
- * @data
- */
- $.doHttpClientGet = function(url, fn) {
- $.getJSON(url, fn);
- }
- /***
- * HttpPut更新数据到服务端
- * @url 业务数据
- * @data
- */
- $.doHttpClientUpdate = function(url, data, fn) {
- $.ajax({
- url: url,
- type: 'PUT',
- data: data,
- dataType: 'json',
- contentType: 'application/json',
- success: fn
- });
- }
- /***
- * HttpDelete删除数据
- * @url 业务数据
- * @data
- */
- $.doHttpClientDelete = function(url, data, fn) {
- $.ajax({
- url: url,
- type: 'DELETE',
- data: data,
- dataType: 'json',
- contentType: 'application/json',
- success: fn
- });
- }
- /***
- * HttpPost保存数据
- * @url 业务数据
- * @data
- */
- $.doHttpClientSave = function(url, data, fn) {
- $.ajax({
- url: url,
- type: 'POST',
- data: data,
- dataType: 'json',
- contentType: 'application/json',
- success: fn
- });
- }
- /***
- * ajax获取服务端数据
- * @url 业务数据
- * @data
- */
- $.doAjaxGet = function(url, fn) {
- //$.getJSON(url, fn);
- $.ajax({
- url: url,
- type: "GET",
- dataType: 'json',
- //data: data,
- contentType: 'application/json',
- success: fn
- });
- }
- $.doAjaxPost = function(url, data, fn) {
- $.ajax({
- url: url,
- type: 'POST',
- data: data,
- dataType: 'json',
- contentType: 'application/json',
- success: fn
- });
- }
- //构造html的通用方法
- $.buildHTML = function(tag, html, attrs) {
- // you can skip html param
- if (typeof (html) != 'string') {
- attrs = html;
- html = null;
- }
- var h = '<' + tag;
- for (attr in attrs) {
- if (attrs[attr] === false) continue;
- h += ' ' + attr + '="' + attrs[attr] + '"';
- }
- return h += html ? ">" + html + "</" + tag + ">" : "/>";
- }
- //构造JsTree的通用方法
- $.fn.buildJsTree = function (url, fn) {
- var object = require(['jstree'], function(){
- $.jstree._themes = "/PlatJS/Scripts/jstree/themes/";
- var myTree = $(this).jstree({
- "json_data": {
- "ajax": {
- "url": url,
- "type": "GET",
- "dataType": "json",
- "contentType": "application/json charset=utf-8",
- "success": fn
- }
- },
- "plugins": ["themes", "json_data", "ui"]
- });
- })
- }
3.4 如何调试?
FireBug for Firefox
Firefox的RestClient插件—Rest Client测试插件
http://localhost:8081/ProductSys.WebAPI/api/order/insertwith?type="insertwith“
[HttpPost]
public HttpResponseMessageInsertWith(Order entity, string type)
http://localhost:8081/ProductSys.WebAPI/api/order/4
[HttpDelete]
public HttpResponseMessage Delete(string id)
3.5 Web异常错误代码
4.2 Javascript-自执行匿名函数
- //Self-Executing Anonymous Func: Part 2 (Public & Private)
- (function( skillet, $, undefined ) {
- //Private Property
- var isHot = true;
- //Public Property
- skillet.ingredient = "Bacon Strips";
- //Public Method
- skillet.fry = function() {
- var oliveOil;
- addItem( "\t\n Butter \n\t" );
- addItem( oliveOil );
- console.log( "Frying " + skillet.ingredient );
- };
- //Private Method
- function addItem( item ) {
- if ( item !== undefined ) {
- console.log( "Adding " + $.trim(item) );
- }
- }
- }( window.skillet = window.skillet || {}, jQuery ));
- <pre name="code" class="javascript">//Public Properties
- console.log( skillet.ingredient ); //Bacon Strips
- //Public Methods
- skillet.fry(); //Adding Butter & Fraying Bacon Strips
- //Adding a Public Property
- skillet.quantity = "12";
- console.log( skillet.quantity ); //12
- //Adding New Functionality to the Skillet
- (function( skillet, $, undefined ) {
- //Private Property
- var amountOfGrease = "1 Cup";
- //Public Method
- skillet.toString = function() {
- console.log( skillet.quantity + " " +
- skillet.ingredient + " & " +
- amountOfGrease + " of Grease" );
- console.log( isHot ? "Hot" : "Cold" );
- };
- }( window.skillet = window.skillet || {}, jQuery ));
- try {
- //12 Bacon Strips & 1 Cup of Grease
- skillet.toString(); //Throws Exception
- } catch( e ) {
- console.log( e.message ); //isHot is not defined
- }</pre><pre name="code" class="javascript"></pre>
- //建议申明对象或数组的写法
- var person = {},
- keys = [];
- //申明复杂对象或数组的写法
- var person = {
- firstName: "Elijah",
- lastName: "Manor",
- sayFullName: function() {
- console.log( this.firstName + " " +
- this.lastName );
- }
- },
- keys = ["123", "676", "242", "4e3"];
4.4 判断对象是否为NULL(c#)
- // <span style="color:#ff0000;">C# 例子. 不要在Javascript中这样写</span>
- if ( someString != null &&
- someString.length > 0 ) {
- //Do something here...
- }
- // C# 例子 检查字符串是否为空
- if ( !string.IsNullOrEmpty(someString) ) {
- //Do something here...
- }
4.5 判断对象是否为NULL(javascript)
- Javascript中的正确写法
- // Simplified JavaScript syntax to check for
- // undefined, null, & empty string values
- if ( someString ) {
- //Do something here...
- }
4.6 设置缺省值(c#)
- <span style="color: rgb(255, 0, 0);">// C# 例子,不要在Javascript这样写</span>
- if ( someString == null ) {
- someString = "default Value";
- }
- // Slightly better, but don't do this either
- someString = someString ? someString : "default value"; <pre name="code" class="javascript">请在Javascript按如下格式写
- // JavaScript syntax to set a default value
- someString = someString || "default value";
- </pre><br>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
4.8 不同类型的比较操作符(===, !==)
4.9 不可取的数组遍历操作符for…in
- var myArray = [], name;
- myArray[5] = "test";
- console.log( myArray.length ); //6
- for ( name in myArray ) {
- console.log( name, myArray[name] );
- //Outputs...
- // 5, test
- }
4.10 正确的数组遍历操作符for…;…;
- var myArray = [], name;
- myArray[5] = "test";
- console.log( myArray.length ); //6
- for ( var i = 0, length = myArray.length; i < length; i++ ) {
- console.log( i, myArray[i] );
- //Outputs...
- // 0, undefined
- // 1, undefined
- // 2, undefined
- // 3, undefined
- // 4, undefined
- // 5, test
- }
- for ( var name in object ) {
- //Your code here
- }
- /* Check if object has property before
- iterating, because functions inherited
- from prototype are also included */
- for ( var name in object ) {
- if ( object.hasOwnProperty(name) ) {
- //Your code here
- }
- }
- define(['Controllers/Main/ListView'], function (ListView) {
- function start() {
- var users = JSON.parse(localStorage.users);
- ListView.render({ users: users });
- }
- return {
- start: start
- };
- });
提供的示例RequireMVC199中,可以看一下ProductSys.WebApi的服务层代码,前端代码看RequireMvc199的WebApplication项目即可。
完整示例,可以看一下ProductList页面的代码,这个示例是完整的,包括文件:
WebApplication 包括:
\Controllers
--ProductController.cs
\ViewJS
\Controllers
\Product
--product-list.js
--product-detail.js
\Views
\Product
--productlist.cshtml
WebApi 包括:
ProductSys.WebApi
\Controllers
--ProductController.cs
ProductSys.ServiceImp
\Service
--ProductService.cs
转载于:https://www.cnblogs.com/johnwood/p/3456029.html
转载CSDN (MVC WebAPI 三层分布式框架开发)相关推荐
- MVC WebAPI 三层分布式框架开发
转载 CSDN (MVC WebAPI 三层分布式框架开发) 转者述:不深不浅,学习直接底部有源码! 前言:SOA(面向服务的架构)是目前企业应用开发过程中普遍采用的技术,基于MVC WebAPI三层 ...
- 转载CSDN博文精选:Android系列开发博客资源汇总
CSDN博客本期热文推荐,为您介绍有关Android应用开发的10个博客,分享他们的日积月累的宝贵经验,希望这些文章对Android开发者们能有所启发和帮助. [1] 张国威:Android从入门到提 ...
- (转载/侵删)mvc与三层结构终极区别
结合自己做过的项目做的总结:三层结构和MVC是从功能性,表现方式两个角度来划分的两种方式 三层结构是从程序功能角度来划分,即每层结构应用到的程序,逻辑,功能一般不同.如:在web应用开发中,后台ser ...
- 游戏开发--开源软件11--Firefly(python 服务端分布式框架)||pygame
2019独角兽企业重金招聘Python工程师标准>>> Firefly是免费.开源.稳定.快速扩展.能 "热更新"的分布式游戏服务器端框架,采用Python编写, ...
- 基于ASP.NET MVC框架开发Web论坛应用程序
我想通过本系列文章从头到尾构建一个完整的ASP.NET MVC论坛应用程序,最终的目的是探讨和推动使用ASP.NET MVC框架构建应用程序的最佳实践. 1. 简介 在本篇中,我想先从全局方面介绍一下 ...
- JAVA分布式快速开发基础平台 iBase4J 推荐 国产 J2EE框架
iBase4J 详细介绍 https://www.oschina.net/p/iBase4J iBase4J项目简介 iBase4J是Java语言的分布式系统架构. 使用Spring整合开源框架. 使 ...
- 使用MVC框架开发网站(一)
概述 本章您将学会: 1.MVC的概念及使用 2.MVC与ASP.NET的区别 3.路由和URL导向 4.控制器和视图 5.模型与模型状态 6.过滤器 7--. 第1章_MVC与ASP.NET的区别 ...
- 使用c++开发分布式框架实践
目前比较流行的分布式框架有dubbo,springcloud,JMX等,都是java实现的,但是在做c++项目时,也有分布式的需求,这时我们可以基于grpc自己设计一套分布式框架. 整体思路如下: C ...
- mvc与三层结构终极区别
又看到有人在问三层架构和MVC的关系,感觉这种问题有点教条化了.因为它们都在逻辑上将应用程序划为三块,凑了一个数字3,就有人非要把它们联系到一起了. 这两个东西我接触有几年了,有一点体会,表达一下: ...
最新文章
- iOS音频——AudioToolbox
- 新功能:阿里云负载均衡SLB支持HTTPS虚拟主机功能(SNI)
- java中executorservice_java中ExecutorService创建方法总结
- 适合打游戏的计算机内存品牌型号,玩游戏电脑内存要多大合适?不同内存容量玩游戏区别实测...
- Boost:boost::bimaps::multiset_of的测试程序
- 最长回文子串Python解法
- html网页设计大赛_HTML5网页设计大赛 || 决赛名单公布
- 一个没有经验的前端工程师,写CSS的时候有什么常见通病?
- Excel 枢纽图(Pivot)快速入门与示例
- Oracle DataGuard 之--Physical DG转换Logical DG
- Android学习2--项目文件列表简单分析
- CentOS 6.9之LVM创建,扩容
- VC 2010下安装OpenCV2.4.4(来自wiki)
- CCF - 201604-2 - 俄罗斯方块
- 瑞昱网卡linux通用驱动下载,realtek网卡通用驱动最新版下载
- 呆萝卜 竞品分析报告
- 兜兜转转。最终还是选择了它——C语言学习历程
- php制作搜索框_搜索功能(search.php)模板制作 - WordPress模板开发
- 简单概述PCIe总线协议
- 关于未来计算机的参考文献,近几年计算机毕业参考文献 哪里有计算机毕业参考文献...
热门文章
- char和byte的区别
- mysql执行语句_实时查看MySQL执行的语句
- docker php伪静态无效,docker 安装 thinkphp+nginx
- form select multiple 某个字段是数组_你知道什么是Select函数吗?
- 炉石传说源代码_python抓取4399上的炉石传说原画,几百张原画拼接成女神画像!...
- 050_Unicode字符官方标准一
- 009_Raphael动画
- java 等待_Java并发之等待/通知机制
- iframe的src怎么携带参数_Java 爬虫遇到需要登录的网站,该怎么办?
- AlarmManager深入浅出