dotnet core webapi 开发学习 (1)
先学会使用 VS Code 参考下面链接学会创建 HelloWorld
https://blog.csdn.net/qq_36051316/article/details/84098496
进入桌面:
cd desktop
md TestApp
cd TestApp
dotnet new webapi
打开我们的vscode,也可以在我们的vscode里面创建
找到 Controllers 文件夹
创建一个文件 (控制器): TestController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace testApp2.Controllers
{
public class TestController : ControllerBase
{
[Route("api/test/get")]
[HttpGet]
public object Get(int i)
{
System.Console.WriteLine("现在访问进接口:api/test/get:"+i);
return "恭喜你访问成功:您输入的数字是:"+i;
}
}
}
这个时候,在终端输入运行的代码:dotnet run
访问 api 地址:
https://localhost:5001/api/test/get
我们就发现访问接口成功啦~如下图