![](/img/trans.png)
[英]What's the difference between two attribute-based routing approaches: HttpGet(“”) and Route(“”)?
[英]What's the difference between [HttpGet] and [HttpGet("{id}")]?
HTTPGET 方法和 HTTPGET("{id}") 方法有什么區別? 用於更新表列的 API 方法是什么?
[HttpGet]
public IActionResult Get()
{
return new JsonResult(users);
}
// GET api/values/5
[HttpGet("{id}")]
public IActionResult Get(string id)
{
return new JsonResult(response);
}
您應該查看 Web API 中的屬性路由。
第一種方法是路由到一個干凈的 api:
/api/controller
第二個指定屬性中的路由值,將通過以下 url 調用:
/api/controller/5
第二個通常用於更新現有查詢,因為您在路由中指定了特定值,而第一個不指定任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.