更新 C_shape/README.md

This commit is contained in:
leo 2025-01-07 17:19:18 +08:00
parent 646d93dde7
commit ddf6a684e0

View File

@ -70,31 +70,31 @@ select c
### 安裝 [下載連接](https://visualstudio.microsoft.com/zh-hant/vs/compare/)
### 下載後若單純架設網站選擇ASP.NET 與 Node.js(之後寫Vue會用到)
### 若需要維護Winform 或是WPF 則選擇.NET桌面開發
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%871.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%871.png)
### 若需要快速建立則直接使用我提供的DEMO去做開發
##
# ASPNET
### 建立新專案
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%872.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%872.png)
### 選擇版本 (這邊以.NET6做教學 目前最新的.NET8)
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%873.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%873.png)
### 啟動
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%874.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%874.png)
### 安裝套件包(NuGet)
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%875.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%875.png)
### 設定資料庫連線
#### 於appsettings.json 中加入
```
//連接MYSQL
"ConnectionStrings": {
"tarefasConnection": "server=140.125.21.65;port=3307;uid=VIP125;pwd=@VIPvip125;database=VIP125"
"tarefasConnection": "server=leovip125.ddns.net;port=3307;uid=VIP125;pwd=@VIPvip125;database=VIP125"
}
```
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%876.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%876.png)
#### 於Program.cs中加入設定
```
@ -105,38 +105,38 @@ select c
opt.UseMySql(connectionString, serverVersion);
});
```
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%877.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%877.png)
### 建立與資料庫table的連線
#### 創建Model
建議將創建的Model名稱第一個字大寫資料庫內部資料表名用小寫這樣較好對比
Model內容需要跟資料表的欄位名稱相對應
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%879.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%879.png)
#### 創建Services
Haskey指的是不會重複的
像是身份證字號這種的就不會重複
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%878.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%878.png)
### 創建控制器
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8710.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8710.png)
### 創建出來的頁面
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8711.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8711.png)
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8712.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8712.png)
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8713.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8713.png)
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8714.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8714.png)
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8715.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8715.png)
##
# WEBAPI
### 建立新專案
### 基本上都與ASPNET相同就這部分要注意
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8717.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8717.png)
### 連接資料庫的方式都與ASPNET一樣這邊只是將ASPNET中的MVC去除View去更專注在後端這邊建立控制器的方式也有點不同
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8718.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8718.png)
### 其餘的就好好看先前提到的ORM框架與LINQ去構建出API即可
### 運行之後:
![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8719.png)
![](http://leovip125.ddns.net:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8719.png)