using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; namespace Knife4jUIDemo.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(); } /// /// 发送一个Post /// /// [HttpPost("CreateUserRequest")] public UserRequest CreateUserRequest([FromBody] UserRequest req) { return req; } } /// /// TheyReqDto /// public sealed class TheyReqDto { /// /// Hobbies /// public string Hobbies { get; set; } = string.Empty; /// /// Behavior /// public string Behavior { get; set; } = string.Empty; } public class UserRequest where TRequest : class { /// /// RequestId /// public string RequestId { get; set; } = string.Empty; /// /// Args /// public TRequest Args { get; set; } } /// /// 请求实体 /// public class PostErrorCodeDto { /// /// 异常信息 /// public string Message { get; set; } /// /// 状态码 /// public ErrorCode ErrorCode { get; set; } } }