using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using WebApi.Models; namespace WebApi.Controllers { [ApiController] [Route("[controller]")] public class TestController : ControllerBase { public TestController() { } [ApiExplorerSettings(IgnoreApi = true)] [Route("/")] public string Home() { return ""; } [HttpPost] [Route("/api/[action]")] public ApiResponse Login([FromBody]LoginRequest model) { if (ModelState.IsValid) { return new ApiResponse { Code = 0, Data = model.UserName }; } return new ApiResponse { Code = 1, Message = "用户名或密码错误" }; } [HttpPost] [Route("/api/[action]")] public ApiResponse Pull([FromBody]PullRequest model) { if (ModelState.IsValid) { return new ApiResponse { Code = 0, Data = new List { new Student{ Id=Guid.NewGuid().ToString(), Name="小明", Class="1班", Sex="男", Nation="汉", IdCardNo="012345678912345678", Number="012345678912345678" }, new Student{ Id=Guid.NewGuid().ToString(), Name="小红", Class="1班", Sex="女", Nation="汉", IdCardNo="112345678912345678", Number="012345678912345678" }, new Student{ Id=Guid.NewGuid().ToString(), Name="小丽", Class="2班", Sex="女", Nation="汉", IdCardNo="112345678912345678", Number="012345678912345678" } } }; } return new ApiResponse { Code = 1, Message = "用户名不能为空" }; } [HttpPost] [Route("/api/[action]")] public ApiResponse Push([FromBody]PushRequest model) { if (ModelState.IsValid) { return new ApiResponse { Code = 0 }; } return new ApiResponse { Code = 1, Message = "数据验证失败" }; } } }