.NetCore -MVC 路由的配置

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
//参数验证,路由的参数验证配置
using Microsoft.AspNetCore.Routing;     
using Microsoft.AspNetCore.Routing.Constraints;

namespace Han.oi.Web
{
    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)
        {
            //引入MVC模块
            services.AddMvc();
        }

        // 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.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}",
                    defaults: new { controller = "Home", action = "index" }
                );
                routes.MapRoute(
                    name: "Han1",
                    template: "{controller}/{action}",
                    defaults: new { controller = "Han1", action = "Time"}
                );

               /*  routes.MapRoute(
                   name: "Tutorial",
                   template: "{controller}/{action}/{name}/{age?}",
                   defaults: new { controller = "Tutorial"}
                ); */

               /*  routes.MapRoute(
                    name: "Tutorial",
                    template: "{controller}/{action}/{age}/{name}",
                    defaults: new { controller = "Tutorial",action="Welcome",name = "韩"},
                    constraints: new { name = new MaxLengthRouteConstraint(5) }
                ); */

                routes.MapRoute(
                   name: "Tutorial_1",
                   template: "{controller}/{action}/{age:range(1,150)}/{name:maxlength(5)}",
                   defaults: new { controller = "Tutorial", action = "Welcome", name = "" }
                );

                /* routes.MapRoute(
                   name: "Tutorial_1",
                   template: "hello/{action}/{age:range(1,150)}/{name:maxlength(5)}",
                   defaults: new { controller = "Tutorial", action = "Welcome", name = "韩" }
                ); */

                routes.MapRoute(
                   name: "jiaocheng_1",
                   template: "jioachen/{action}.html"
                );
            });


        }
    }
}
引入包的名称在项目根目录输入(连接Mysql的数据包)

dotnet add package Pomelo.EntityFrameworkCore.MySql --version 2.1.4

这个版本引入用不了,换个版本
dotnet add package Pomelo.EntityFrameworkCore.MySql --version 2.0.1
可以用

  

 
1.创建解决方案
    dotnet new sln -n Ken.Tutorial
2.创建.NetCore项目
    dotnet new web -n Ken.Tutorial.Web
3.将项目移到解决方案中
   dotnet sln add Ken.Tutorial.Web 
C#中的jar包配置

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Folder Include="wwwroot"/>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App"/>
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All"/>
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.1"/>
  </ItemGroup>
</Project>

EF Core + Linq to entity 访问数据库

EF Core + 原生SQL 访问数据库

https://www.cnblogs.com/ken-io/p/aspnet-core-tutorial-entity-framework-core-mysql.html
原文地址:https://www.cnblogs.com/han-guang-xue/p/10559265.html