zoukankan      html  css  js  c++  java
  • 30-RoutingMiddleware介绍以及MVC引入

    1-构建路由

     public class Startup
        {
            // This method gets called by the runtime. Use this method to add services to the container.
            // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddRouting(); //如果采用第一种方式,必要加上些条命令
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
    
               //第一种方式
                app.UseRouter(myhandler=>{
                    myhandler.MapGet("action",context=>context.Response.WriteAsync("this is action") );
                });
    
              //第一种方式,自己构建route
                RequestDelegate handler = context =>  context.Response.WriteAsync("i am router"); 
                var router = new Route(
                    new RouteHandler(handler),
                    "myaction",
                    app.ApplicationServices.GetRequiredService<IInlineConstraintResolver>()     
                );
                app.UseRouter(router);
    
                //第二种方式
                app.Map("/task",taskApp=>{ //路由匹配
                    taskApp.Run(async (context)=>{
                        await context.Response.WriteAsync("i am task");
                    });
                });
    
            }
        }
  • 相关阅读:
    Servlet
    javaBean
    堆排序
    快速排序
    JSP9大内置对象
    include指令与<jsp:include>动作标识
    JSP指令标识
    TreeSet
    使用Docker存储之卷Volume
    Java学习之HttpClient的GET与POST请求
  • 原文地址:https://www.cnblogs.com/qinzb/p/9346282.html
Copyright © 2011-2022 走看看