前言:有时候项目会要求规范api的路径,这时候就需要我们去根据 规定 去定义路由了
今天做了个简单的测试,并用postman进行了测试
[Route("Nuc/api/proc/[controller]")] [ApiController] public class RouteTestController : ControllerBase { [HttpGet] [Route("GetData")] public IActionResult GetData() { return Ok(new { code=21,msg="success"}); } [HttpPost] [Route("PostData")] public IActionResult PostData(Data data) { if (data==null) { return Ok(new { code = 7, msg = "No Data" }); } if (data.Uname=="admin" && data.USign=="147258") { return Ok(new { code = 21, msg = "success" }); } return Ok(new { code = 7, msg = "用户名或密码不正确" }); } } public class Data { public string Uname { get; set; } public string USign { get; set; } }
原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/269675.html