using Knife4jUIDemo;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
namespace AspNetCore6Api.Controllers
{
///
/// 中文这是一个Get请求这是一个Get请求
///
[ApiController]
[Route("api/WeatherForecast/[action]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger _logger;
public WeatherForecastController(ILogger logger)
{
_logger = logger;
}
///
/// 得到一个ErrorCode
///
///
[HttpGet]
public ErrorCode GetErrorCode()
{
return ErrorCode.Success;
}
[HttpGet]
public ErrorCode GetErrorCode2(ErrorCode errorCode)
{
return errorCode;
}
[HttpGet]
public IActionResult GetErrorCode4(ErrorCode errorCode)
{
return new JsonResult(new PostErrorCodeDto() { Message = "a", ErrorCode = errorCode });
}
///
/// 发送一个Post
///
///
[HttpPost]
public PostErrorCodeDto PostErrorCode([FromBody] PostErrorCodeDto PostErrorCodeDto)
{
return PostErrorCodeDto;
}
///
/// 这是一个Get请求
///
///
[HttpGet]
public IEnumerable Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
///
/// 请求实体
///
public class PostErrorCodeDto
{
///
/// 异常信息
///
public string Message { get; set; }
public WeatherForecast WeatherForecast { get; set; }
///
/// 状态码
///
public ErrorCode ErrorCode { get; set; }
}
}