五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

asp.net core web api 控制類定義技巧

2023-02-20 22:32 作者:大衣哥編程  | 我要投稿
  1. ation放在類的外部,例如:

    ???[Route("api/[controller]/[action]")]
    ? ? [ApiController]
    ? ? public class SystemInfoController : ControllerBase

    此種類型,則action對(duì)整個(gè)類起作用,路由訪問的時(shí)候,action可被類的方法名代替:

    [Route("api/[controller]/[action]")]
    ? ? [ApiController]
    ? ? public class SystemInfoController : ControllerBase
    ? ? {
    ????? ? // 請(qǐng)求方式為:?http://localhost:7216/api/SystemInfo/Do1
    ????? ? [HttpGet]
    ????? ? public string Do1()
    ????? ? {
    ????????? ? return "hello ";
    ????? ? }

    ????? ? // 請(qǐng)求方式為:?http://localhost:7216/api/SystemInfo/Do2?id=def
    ????? ? [HttpGet]
    ????? ? public string Do2(string id)
    ????? ? {
    ????????? ? return "hello: " + id;
    ????? ? }

    ????? ? // 請(qǐng)求方式為:?http://localhost:7216/api/SystemInfo/Do3?id=def
    ????? ? [HttpGet]
    ????? ? public string Do3(string id)
    ????? ? {
    ????????? ? return "good: " + id;
    ????? ? }

    注意:..../方法名 + ? + 參數(shù)=?


2.?[action]放在類的方法定義上面,則action 僅僅對(duì)該方法有效,如下:

[Route("api/[controller]")]

? ? [ApiController]

? ? public class SystemManagerController : ControllerBase

? ? {

? ? ? ? // 以下2個(gè)都是http get 方法,但是路由不同,分別為 api/SystemManager、api/SystemManager/1、api/SystemManager/ab/28

? ? ? ? [HttpGet]

? ? ? ? public string GetC()

? ? ? ? {

? ? ? ? ? ? return "hello world";

? ? ? ? }


? ? ? ? [HttpGet("{id}")]

? ? ? ? public string GetD(int id)

? ? ? ? {

? ? ? ? ? ? return "hello world 0:";

? ? ? ? }


? ? ? ? // 注意:[action] 既可以加在類外頭部(對(duì)類起作用),也可以放在方法頭上面(僅對(duì)該方法有用)

? ? ? ? // 方法外面[action]修飾,則訪問方法為:http://localhost:5049/api/SystemManager/GetE/222

? ? ? ? [HttpGet("[action]/{id}")]

? ? ? ? public string GetE(int id)

? ? ? ? {

? ? ? ? ? ? return "hello world 00:" + id;

? ? ? ? }


? ? ? ? // 請(qǐng)求url:http://localhost:5049/api/SystemManager/GetF?id=985

? ? ? ? [HttpGet("[action]")]

? ? ? ? public string GetF(int id)

? ? ? ? {

? ? ? ? ? ? return "hello world 00:" + id;

? ? ? ? }



? ? ? ? [HttpGet("ab/{id}")]? ? // 注意:通過ab來(lái)區(qū)分路由,以便多個(gè)httpget得以調(diào)用

? ? ? ? public string GetDF(int id)

? ? ? ? {

? ? ? ? ? ? return "hello world 1: " + id;

? ? ? ? }


? ? ? ? [HttpGet("abc/{id}")]? ? // 注意:通過ab來(lái)區(qū)分路由,以便多個(gè)httpget得以調(diào)用

? ? ? ? public string GetDFG(int id)

? ? ? ? {

? ? ? ? ? ? return "hello world 2 :"+id;


? ? ? ? }

? ? }


3. 部分截圖


asp.net core web api 控制類定義技巧的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
临城县| 濉溪县| 嘉禾县| 正镶白旗| 榆林市| 香港 | 防城港市| 东乌珠穆沁旗| 安徽省| 宜兰市| 满洲里市| 分宜县| 肇庆市| 竹溪县| 兴安县| 开阳县| 青川县| 新田县| 卢氏县| 建湖县| 股票| 独山县| 石阡县| 嘉鱼县| 章丘市| 柳河县| 洛南县| 黄梅县| 那曲县| 安化县| 深水埗区| 西乌珠穆沁旗| 陆良县| 图片| 大竹县| 东辽县| 德钦县| 建瓯市| 拉萨市| 昂仁县| 淳安县|