namespace jxc.Api; public class ApiResult { ///<summary> ///是否正常返回 ///</summary> public bool Success { get; set; } ///<summary> ///处理消息 ///</summary> public string? Message { get; set; } } public class ApiDataResult<T> : ApiResult { ///<summary> ///结果集 ///</summary> public T? Data { get; set; } ///<summary> ///冗余结果 ///</summary> public object? OValue { get; set; } }
/// <summary> /// 新增对象 /// </summary> /// <param name="item"></param> /// <returns></returns> [HttpPost] public virtual IActionResult AddItem([FromBody] DtoInventory item) { _logger.LogInformation("InventoryController测试记录日志"); _inventoryService.AddItem(item); return new JsonResult(new ApiResult() { Success = true, Message = "添加成功" }); }
[HttpGet] public IActionResult GetAllItems() { IEnumerable<DtoInventory> items = _inventoryService.GetAllItems(); return new JsonResult(new ApiDataResult<IEnumerable<DtoInventory>>() { Success = true, Message = "获取成功", Data = items, OValue = null }); }标签:返回,set,Success,get,ApiResult,api,new,格式,public From: https://www.cnblogs.com/hlm750908/p/18661814