002.AngularJs调用Restful实现CRUD

本节咱们主要给你们介绍AngularJs如何调用Restful,实现数据的CRUD。前端

主要用到的技术:后端

后端:ASP.NET WebApi + SQLServer2008api

前端:AngularJs,Bootstrap3工具

主要用到的开发工具开发工具

后端:VisualStudio2013 + SQLServer2008测试

前端:WebStorm8spa

 

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/test3d

请输入咱们的请求地址和请求方式code

image

查看返回结果orm

image

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

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

image

查看返回结果

image

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

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

image

查看返回结果

image

 

(未完待续)

相关文章
相关标签/搜索