zoukankan      html  css  js  c++  java
  • Core下简易WebApi

    代码很粗糙~

    粘贴github地址

    https://github.com/htrlq/MiniAspNetCoreMini

    demo

     1     public class Startup
     2     {
     3         public Startup(IConfiguration configuration)
     4         {
     5             Configuration = configuration;
     6         }
     7 
     8         public IConfiguration Configuration { get; }
     9 
    10         // This method gets called by the runtime. Use this method to add services to the container.
    11         public void ConfigureServices(IServiceCollection services)
    12         {
    13             services.AddMvc();
    14 
    15             services
    16                 .AddApiServerInit()
    17                 .AddApiServer<MyController>();
    18         }
    19 
    20         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    21         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    22         {
    23             if (env.IsDevelopment())
    24             {
    25                 app.UseDeveloperExceptionPage();
    26             }
    27 
    28             app.UseMvc();
    29 
    30             app.UseRouter(route =>
    31             {
    32                 route.UserApiServer();
    33             });
    34         }
    35     }
    36 
    37     public enum OrderSort
    38     {
    39         DoExecute,
    40         Success,
    41         NotPay
    42     }
    43 
    44     public class ParamOrderSort
    45     {
    46         [Required]
    47         public Guid? UserId { get; set; }
    48         [Required]
    49         public OrderSort? Type { get; set; }
    50         public int? PageIndex { get; set; }
    51         public int? PageSize { get; set; }
    52     }
    53 
    54     public class MyController : ApiServerBase
    55     {
    56         [HttpGet]
    57         [HttpPost]
    58         public async Task Show(ParamOrderSort param)
    59         {
    60             await context.HttpContext.Response.WriteAsync($"{param.UserId} {param.Type} {param.PageIndex} {param.PageSize}");
    61         }
    62 
    63         public MyController(IHttpContextAccessor context) : base(context)
    64         {
    65         }
    66     }
  • 相关阅读:
    项目范围管理定义范围
    项目时间管理估算活动资源
    项目时间管理排列活动顺序
    强悍!ultraEdit的文本比较
    网页刷流量软件开发中的困惑
    关于淘宝CSV格式的研究
    HTTP session登陆处理与登陆保持
    用ps将自己的图片字节数变最小
    通过TApplicationEvents响应消息
    有的女人就像易语言
  • 原文地址:https://www.cnblogs.com/NCoreCoder/p/9146273.html
Copyright © 2011-2022 走看看