[HttpGet]和[HttpGet(“{id}”)]之间有什么区别?

问题描述 投票:-2回答:1

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);
}
asp.net api
1个回答
0
投票

您应该在Web API中查看Attribute Routing

第一种方法是路由到干净的api:

/api/controller

第二个指定属性中的路由值,将通过以下url调用:

/api/controller/5

第二个通常用于更新现有查询,因为您在路由中指定了特定值,而第一个未指定任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.