![](/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.