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     }
  • 相关阅读:
    新手学逆向,调试abexcm1过程
    (原创)渗透某国工业系统
    (原创)对某国的一次渗透
    汇编笔记 RETF
    汇编笔记 CALL(1)
    汇编笔记 RET
    大小写转换
    JDK下载太慢?让国内镜像帮助你
    Win7,docker安装后,创建虚拟机分配不了ip错误 err: exit status 255
    Spring事务传播实践与Spring“事务失效”
  • 原文地址:https://www.cnblogs.com/NCoreCoder/p/9146273.html
Copyright © 2011-2022 走看看