你能告诉我什么是控制器方法 GetProfileById 的正确 url 与属性 'id' 我尝试了很多 url,如 ' http://localhost:5000/api/Profile/GetProfileById/1 '、' http://localhost:5000/ api/Profile/ProfileById/1 ',' http://localhost:5000/api/ProfileById/1 ' 但 Postman 显示消息 'Cannot Get and my url'
这是代码:
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SocialNetwork.Repositories;
using SocialNetwork.Repositories.GenericRepository;
namespace SocialNetwork.Controllers
{
[Route("/api/[controller]")]
public class ProfileController : Controller
{
private readonly ProfileRepository repository;
public ProfileController(IProfileRepository repository)
{
this.repository = (ProfileRepository)repository;
}
[HttpGet("{id}")]
[ProducesResponseType(200, Type = typeof(Profile))]
[ProducesResponseType(404)]
public async Task<ActionResult<Profile>> GetProfileById(int id)
{
var profile = await repository.GetById(id);
if(profile != null)
{
return new OkObjectResult(Json(profile));
}
return NotFound();
}
}
}
波斯汪
慕哥6287543
相关分类