一,如下图
二,构建好框架,将不必要的包删掉
三,添加路由
1
2
3
4
5
6
7
8
9
10
|
app.useendpoints(endpoints =>
{
endpoints.mapcontrollerroute(
name: "default" ,
pattern: "{controller=home}/{action=index}/{id?}" );
endpoints.mapareacontrollerroute(
name: "areas" , "areas" ,
pattern: "{area:exists}/{controller=home}/{action=index}/{id?}" );
});
|
四,添加控制器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
using system;
using system.collections.generic;
using system.linq;
using system.threading.tasks;
using microsoft.aspnetcore.http;
using microsoft.aspnetcore.mvc;
namespace nld.houtai.areas.api.controllers
{
[apicontroller]
[area( "api" )]
[route( "api/[controller]/[action]" )]
public class usercontroller : controllerbase
{
[httpget]
public string get ()
{
return "get" ;
}
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://www.cnblogs.com/May-day/p/12213208.html