weiApi——项目WeiApi创建

1.

这里写图片描述

2.

这里写图片描述

3.

这里写图片描述

上面三步完成 weiApi 项目创建

这里写图片描述


运行项目

这里写图片描述


新建一个Products API
(1)、添加ProductController
(2)、选择empty 控制器

这里写图片描述


前后台代码

html

这里写图片描述

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script>
        $(function () {
            $("#GetProductList").click(function () {
                $.ajax({
                    type: "get",
                    url: "/api/products/product/GetProductList",
                    success: function (data, status) {

                    }
                });
            });

            $("#GetProduct").click(function () {
                $.ajax({
                    type: "get",
                    url: "/api/products/product/get?productId=111",
                    success: function (data, status) {

                    }
                });
            });

            $("#AddProduct").click(function () {
                $.ajax({
                    type: "post",
                    url: "/api/products/product/add",
                    contentType: 'application/json',
                    data: JSON.stringify({ Title: "脑白金", CreateTime: "1988-09-11" }),
                    success: function (data, status) { }
                });
            });

            $("#UpdateProduct").click(function () {
                $.ajax({
                    type: "post",
                    url: "/api/products/product/update?productId=111",
                    contentType: 'application/json',
                    data: JSON.stringify({ Title: "脑白金升级版", CreateTime: "1988-09-11" }),
                    success: function (data, status) { }
                });
            });

            $("#DeleteProduct").click(function () {
                $.ajax({
                    type: "delete",
                    url: "/api/products/product/delete?productId=111",
                    contentType: 'application/json',
                    success: function (data, status) { }
                });
            });

        });
    </script>
</head>
<body>
    <input type="button" id="GetProductList" value="获取产品分页API" /><br />
    <input type="button" id="GetProduct" value="获取单个产品API" /><br />
    <input type="button" id="AddProduct" value="产品新增API" /><br />
    <input type="button" id="UpdateProduct" value="产品更新API" /><br />
    <input type="button" id="DeleteProduct" value="产品删除API" /><br />
</body>
</html>

重点内容 后端

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace WebApplication1.Controllers
{
    [RoutePrefix("api/products")]
    public class ProductController : ApiController
    {
        //获取产品分页API: api/products/product/getList 
        [HttpGet, Route("product/getList")]
        public List<Product> GetProductList()
        {
            throw new NotImplementedException();
        }

        //获取单个产品API: api/products/product/get?productId=产品ID 
        [HttpGet, Route("product/get")]
        public Product GetProduct(int productId)
        {
            throw new NotImplementedException();
        }

        //产品新增API: api/products/product/add
        [HttpPost, Route("product/add")]
        public Guid AddProduct(Product product)
        {
            throw new NotImplementedException();
        }

        //产品更新API: api/products/product/update?productId=产品ID
        [HttpPost, Route("product/update")]
        public void UpdateProduct(int productId, Product product)
        {
            throw new NotImplementedException();
        }

        //产品删除API: api/products/product/delete?productId=产品ID 
        [HttpDelete, Route("product/delete")]
        public void DeleteProduct(int productId)
        {
            throw new NotImplementedException();
        }
    }

    public class Product 
    {
        public int productId { get; set; }

        public string Title { get; set; }

        public DateTime CreateTime { get; set; }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值