比如下面的 CreateOrderAsync
Action 直接使用自己的路由 v{version:apiVersion}/orders
, 忽略 OrderController
配置的路由前缀
[ApiController]
[ApiVersion("1")]
[Route("v{version:apiVersion}/users/{userId}")]
public class OrderController : BaseApiController
{
[HttpPost("v{version:apiVersion}/orders")]
public async Task<IActionResult> CreateOrderAsync([FromBody] CreatingOrderDto createOrderDto)
{
//...
}
}
Action 路由以 /
或者 ~/
开头即可 override
[HttpPost("/v{version:apiVersion}/orders")]
public async Task<IActionResult> CreateOrderAsync([FromBody] CreatingOrderDto createOrderDto)
{
//...
}
或者
[HttpPost("~/v{version:apiVersion}/orders")]
public async Task<IActionResult> CreateOrderAsync([FromBody] CreatingOrderDto createOrderDto)
{
//...
}