using HealthLiteracy.Models.Dto; using Microsoft.AspNetCore.Mvc; using System.ComponentModel; namespace HealthLiteracy.Controllers { /// <summary> /// 测试控制器,遵循RESTful接口设计原则 /// </summary> [Route("api/[controller]")] [ApiController] public class TTController : ControllerBase { /// <summary> /// 添加方法 /// </summary> /// <param name="user"></param> /// <returns></returns> [HttpPost] public IActionResult Post([FromBody] AccountDto user) { return Created($"api/users/{user.Account}", user); } /// <summary> /// 更新方法 /// </summary> /// <param name="id"></param> /// <param name="user"></param> /// <returns></returns> [HttpPut("{id}")] public IActionResult Put(int id, [FromBody] AccountDto user) { return Created($"api/users/{user.Account}", user); } /// <summary> /// 获取所有注释 /// </summary> [HttpGet] public void Get() { } /// <summary> /// 根据ID获取某一个对象 /// </summary> /// <param name="id"></param> [HttpGet("{id}")] public void Get(int id) { } /// <summary> /// 删除方法 /// </summary> /// <param name="id"></param> [HttpDelete("{id}")] public void Delete(int id) { } /// <summary> /// 删除另一个方法 /// </summary> /// <param name="user"></param> [HttpDelete] //public void Delete([FromBody] AccountDto user) public void DeleteDDD([FromBody] AccountDto user) { } } }
下面是生成的接口api: