素材巴巴 > 程序开发 >

AngularJs调用Restful实现CRUD - AngularJs

程序开发 2023-09-04 22:35:42

本节我们主要给大家介绍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

(未完待续)

转载于:https://www.cnblogs.com/branton-design/p/5909948.html


标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。