Commit 506c929b authored by 李嘉琪's avatar 李嘉琪

add:增加初始项目

parents
*/bin/*
*/obj/*
\ No newline at end of file
using Microsoft.AspNetCore.Mvc;
using netcoreApi.Dto;
namespace netcoreApi.Controller
{
/// <summary>
/// 测试类
/// </summary>
[ApiController]
[Route("api/[controller]/[action]")]
public class TestController
{
/// <summary>
/// 获取字符串
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
[HttpGet]
public string HelloIndex(string str)
{
return str + "sdcc";
}
/// <summary>
/// 获取用户
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
[HttpPost]
public User GetUser(User user)
{
return user;
}
}
}
\ No newline at end of file
namespace netcoreApi.Dto
{
public class User
{
public string Name { get; set; }
public int Age { get; set; }
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace netcoreApi
{
/// <summary>
/// 入口
/// </summary>
public class Program
{
/// <summary>
/// 主函数
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
/// <summary>
/// 创建程序
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59289",
"sslPort": 44311
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"netcoreApi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
namespace netcoreApi
{
/// <summary>
/// 配置API类
/// </summary>
public class Startup
{
/// <summary>
/// 构造
/// </summary>
/// <param name="configuration"></param>
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
/// <summary>
/// Configuration
/// </summary>
/// <value></value>
public IConfiguration Configuration { get; }
/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
//swagger注入
services.AddSwaggerGen(c=>{
c.SwaggerDoc("api",new OpenApiInfo(){
Version = "1.0",
Title = "My API",
Description = "APi描述",
Contact = new OpenApiContact(){
Name = "LJQ",
Email = "9646414088@qq.com",
Url = new Uri("http://www.baidu.com")
}
});
string swaggerFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"SwaggerDemo.xml");
c.IncludeXmlComments(swaggerFilePath);
});
}
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//swagger
app.UseSwagger();
app.UseSwaggerUI(c=>{
c.SwaggerEndpoint("/swagger/api/swagger.json","test1");
});
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
<?xml version="1.0"?>
<doc>
<assembly>
<name>netcoreapi</name>
</assembly>
<members>
<member name="T:netcoreApi.Controller.TestController">
<summary>
测试类
</summary>
</member>
<member name="M:netcoreApi.Controller.TestController.HelloIndex(System.String)">
<summary>
获取字符串
</summary>
<param name="str"></param>
<returns></returns>
</member>
<member name="M:netcoreApi.Controller.TestController.GetUser(netcoreApi.Dto.User)">
<summary>
获取用户
</summary>
<param name="user"></param>
<returns></returns>
</member>
<member name="T:netcoreApi.Program">
<summary>
入口
</summary>
</member>
<member name="M:netcoreApi.Program.Main(System.String[])">
<summary>
主函数
</summary>
<param name="args"></param>
</member>
<member name="M:netcoreApi.Program.CreateHostBuilder(System.String[])">
<summary>
创建程序
</summary>
<param name="args"></param>
<returns></returns>
</member>
<member name="T:netcoreApi.Startup">
<summary>
配置API类
</summary>
</member>
<member name="M:netcoreApi.Startup.#ctor(Microsoft.Extensions.Configuration.IConfiguration)">
<summary>
构造
</summary>
<param name="configuration"></param>
</member>
<member name="P:netcoreApi.Startup.Configuration">
<summary>
Configuration
</summary>
<value></value>
</member>
<member name="M:netcoreApi.Startup.ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary>
This method gets called by the runtime. Use this method to add services to the container.
</summary>
<param name="services"></param>
</member>
<member name="M:netcoreApi.Startup.Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder,Microsoft.AspNetCore.Hosting.IWebHostEnvironment)">
<summary>
This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
</summary>
<param name="app"></param>
<param name="env"></param>
</member>
</members>
</doc>
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Https":{
"Url": "http://localhost:5000"
}
}
}
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DocumentationFile>SwaggerDemo.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.1" />
</ItemGroup>
</Project>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment