zoukankan      html  css  js  c++  java
  • 002.AngularJs调用Restful实现CRUD

    本节我们主要给大家介绍AngularJs如何调用Restful,实现数据的CRUD。

    主要用到的技术:

    后端:ASP.NET WebApi + SQLServer2008

    前端:AngularJs,Bootstrap3

    主要用到的开发工具

    后端:VisualStudio2013 + SQLServer2008

    前端:WebStorm8

    1.创建后端项目AngularJs_WebApi

    1.1建立空解决方案名称AngularJs_WebApi

    image

    1.2 创建AngularJs_WebApi_Server服务端项目

    image

    1.3 选择空的WebApi项目,并创建

    image

    image

    1.4 新建控制器TestController类(用于测试)

    image

    image

    image

    1.5 编写TestController.cs实现代码

    using System.Net.Http;
    using System.Web.Http;
    
    namespace AngularJs_WebApi_Server.Controllers
    {
        public class TestController : ApiController
        {
            public HttpResponseMessage Get()
            {
                return new HttpResponseMessage()
                {
                    Content = new StringContent("我是通过Get请求的")
                };
            }
    
            public HttpResponseMessage Post()
            {
                return new HttpResponseMessage()
                {
                    Content = new StringContent("我是通过Post请求的")
                };
            }
    
            public HttpResponseMessage Put()
            {
                return new HttpResponseMessage()
                {
                    Content = new StringContent("我是通过Put请求的")
                };
            }
        }
    }

    1.6 通过Chrome应用程序REST Console测试刚才发布的服务(如果没有可以到应用商店中去下载)

    image

    测试Get请求http://localhost:31194/api/test

    请输入我们的请求地址和请求方式

    image

    查看返回结果

    image

    测试Post请求http://localhost:31194/api/test

    请输入我们的请求地址和请求方式

    image

    查看返回结果

    image

    测试Put请求http://localhost:31194/api/test

    请输入我们的请求地址和请求方式

    image

    查看返回结果

    image

    (未完待续)

  • 相关阅读:
    Hashmap实现原理
    策略模式
    Google Drive ubuntu
    numix Docky
    Google Drive 和 Dropbox 同步同一个文件夹目录
    sublime text 2
    matlab cell
    liteide
    taglist and nerdtree
    codeblocks
  • 原文地址:https://www.cnblogs.com/angularjs/p/3782334.html
Copyright © 2011-2022 走看看