NET7下的WEB API示例

发布时间 2023-08-04 09:39:14作者: 牛腩

NET7下的WEB API示例

 

    [Route("api/[controller]")]
    [ApiController]
    public class ShopADController : ControllerBase
    {
        private readonly IRepository<Model.ShopAD, int> _shopAD;

        public ShopADController(IRepository<ShopAD, int> shopAD)
        {
            _shopAD = shopAD;
        }
        
         //http://localhost:5000/api/shopad
        [HttpGet]
        public string Get() { 
        return "getget";
        }

    //http://localhost:5000/api/shopad/banner
        [HttpGet("banner")]
        public List<Model.ShopAD> Banner() {
            return _shopAD.GetAllList(a => a.Remark == "banner");
        }
    }