XUCore.Template.EasyFreeSql 9.6.26

dotnet new install XUCore.Template.EasyFreeSql::9.6.26
                    
This package contains a .NET Template Package you can call from the shell/command line.

XUCore.Template.EasyFreeSql

XUCore.Template.EasyFreeSql

基于 FreeSql 的单层应用快速开发项目模板,生成 WebApi 项目

使用模板

本地安装模板:可详情见 install-template.bat 文件内

本地安装模板步骤

如果已经装过旧版,可以先执行下面命令进行卸载:


dotnet new -u xfreesql2

然后安装指定版本:


dotnet new --install XUCore.Template.EasyFreeSql::{version}

创建项目

切换到指定创建的目录。

假设我们需要在 E:\demo 创建,

那么先切换到该目录


cd E:\demo

然后执行下面命令创建项目


dotnet new xfreesql2 -n MyTest -o .

这里的 xfreesql2 是使用模板短名称。

MyTest 为新创建的项目名称。

avatar

本地构建项目镜像到 Docker(如果使用 jenkins 可以直接在 jenkins 里配置)

前提是 dockerfile 需要放在项目根目录,而非启动项目的目录

不采用微软自带的 dockerfile,我们需要手工打包发布。

1、切换到项目目录


cd E:\demo\MyTest.WebApi2

2、本地编译


dotnet build -c Release

3、本地发布(实际发布到当前项目的 bin/Release/net5.0/publish/ 目录)


dotnet publish -c Release

4、打包进 docker


docker build -t mytest:0.0.1 .

从控制台中,我们可以看到打包过程


E:\MyTest>docker build -t mytest:0.0.1 .
[+] Building 14.7s (12/20)
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0                                                  0.0s
[+] Building 15.1s (12/20)
 => [internal] load build definition from Dockerfile                                                               0.0s
[+] Building 30.4s (12/20)
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
[+] Building 56.7s (21/21) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0                                                  0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:5.0                                               0.0s
 => [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:5.0                                                              0.0s
 => [internal] load build context                                                                                  1.2s
 => => transferring context: 119.91MB                                                                              1.2s
 => [base 1/5] FROM mcr.microsoft.com/dotnet/aspnet:5.0                                                            0.0s
 => CACHED [build 2/7] WORKDIR /src                                                                                0.0s
 => CACHED [build 3/7] COPY [MyTest.WebApi2/MyTest.WebApi2.csproj, MyTest.WebApi2/]                                   0.0s
 => CACHED [build 4/7] RUN dotnet restore "MyTest.WebApi2/MyTest.WebApi2.csproj"                                     0.0s
 => [build 5/7] COPY . .                                                                                           0.4s
 => [build 6/7] WORKDIR /src/MyTest.WebApi2                                                                         0.0s
 => [build 7/7] RUN dotnet build "MyTest.WebApi2.csproj" -c Release -o /app/build                                  43.2s
 => [publish 1/1] RUN dotnet publish "MyTest.WebApi2.csproj" -c Release -o /app/publish                            11.5s
 => CACHED [base 2/5] ADD [sources.list, /etc/apt/]                                                                0.0s
 => CACHED [base 3/5] RUN rm /etc/localtime                                                                        0.0s
 => CACHED [base 4/5] RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime                                   0.0s
 => CACHED [base 5/5] WORKDIR /app                                                                                 0.0s
 => CACHED [final 1/2] WORKDIR /app                                                                                0.0s
 => CACHED [final 2/2] COPY --from=publish /app/publish .                                                          0.0s
 => exporting to image                                                                                             0.0s
 => => exporting layers                                                                                            0.0s
 => => writing image sha256:addb11051debc4cf74c7d048d15cafdb7edbf121ae54fc55960f1b46bce94fda                       0.0s
 => => naming to docker.io/library/mytest:0.0.1                                                                    0.0s
 => => #   Determining projects to restore...
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

结束后,我们使用 docker images 查看打包好的镜像


E:\MyTest>docker images
REPOSITORY                        TAG       IMAGE ID       CREATED        SIZE
mytest                            0.0.1     addb11051deb   20 hours ago   258MB
mcr.microsoft.com/dotnet/sdk      5.0       1cfcb8589c29   12 days ago    631MB
mcr.microsoft.com/dotnet/aspnet   5.0       592a912e0dcb   12 days ago    205MB

3、启动容器


docker run --name my-test -d -p 8090:8090 mytest:0.0.1

启动后我们通过 docker ps -a 查看运行的镜像


E:\MyTest>docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS                       PORTS     NAMES
35c9010404ae   mytest:0.0.1   "dotnet MyTest.WebAp…"   5 minutes ago   Exited (139) 4 minutes ago             my-test

4、浏览器访问

http://127.0.0.1:8090/swagger

此时容器会报错,因为在创建项目后配置文件内需要修改数据库连接地址(进入容器后,我们的所有数据库地址以及其他相关地址都需要修改为内网访问,或者公网访问)

我们可以查看容器的日志,方便我们定位错误


docker logs 35c9010404ae

此时,在容器日志,我们看到


fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]

客户端接入 API


API 隐藏操作说明
head value 说明
limit-mode contain or ignore contain 的意思是指定输出字段, ignore 的意思是忽略指定字段
limit-field 字段集合 指定要输出或要忽略的字段,以英文逗号分隔,如:column1,column2,column3
limit-field-rename 要重命名的字段 字段以输出为准,比如:code=c,subCode=sub,data=data,nickname=userNickName
limit-resolver camelcase or default camelcase 的意思是指定输出小驼峰字段, default 的意思是默认输出大小写字段
limit-date-unix true or false 当设置为true的时候 则是所有DateTime时间全部返回时间戳,当为false的时候不启用
limit-date-format 日期格式化字符串 比如:yyyy-MM-dd'T'HH:mm:ss'Z' 返回的数据如:2021-01-06T10:03:38Z
1、如何改变 DateTime 的格式?

我们需要在 http 请求的时候,在 head 里加入配置

head value 说明
limit-date-unix true or false 当设置为true的时候 则是所有DateTime时间全部返回时间戳,当为false的时候不启用
limit-date-format 日期格式化字符串 比如:yyyy-MM-dd'T'HH:mm:ss'Z' 返回的数据如:2021-01-06T10:03:38Z

注意: limit-date-unix的优先级要大于limit-date-format


2、如何重命名和指定输出需要的字段?
head value 说明
limit-mode contain or ignore contain 的意思是指定输出字段, ignore 的意思是忽略指定字段
limit-field 字段集合 指定要输出或要忽略的字段,以英文逗号分隔,如:column1,column2,column3
limit-field-rename 要重命名的字段 字段以输出为准,比如:code=c,subCode=sub,data=data,nickname=userNickName

注意:当你使用重命名limit-field-rename字段后,指定输出的字段limit-field要以重命名后的字段名为准,大小写也请依照你重命名后的格式。

任何指定输出,均不影响原始定义的结构。

3、如何指定输出小驼峰字段?
head value 说明
limit-resolver camelcase or default camelcase 的意思是指定输出小驼峰字段, default 的意思是默认输出大小写字段

任何指定输出,均不影响原始定义的结构。

示例一

如下表设置:

设置 说明
limit-mode contain 指定匹配输出模式
limit-field code,subCode,data,userId,userNickName,entName 设置需要的字段集合,英文逗号分隔

示例二

如下表设置:

设置 说明
limit-mode contain 指定匹配输出模式
limit-field code,sub,data,totalPages,totalRecords,pageDatas,createTime,nickName,entId,entName 设置需要的字段集合,英文逗号分隔,并以重命名后的字段为准设置输出字段
limit-field-rename subcode=sub,data=data,items=pageDatas,userNickName=nickName 重命名字段

示例三

如下表设置:

设置 说明
limit-mode ignore 指定忽略输出模式
limit-field code,subCode,message,userId,userNickName,entName,productType,userHeadImg_48 设置要忽略的字段集合,英文逗号分隔

示例四

如下表设置:

设置 说明
limit-mode ignore 指定忽略输出模式
limit-field code,subCode,message,userId,userNickName,entName,productType,userHeadImg_48 设置要忽略的字段集合,英文逗号分隔
limit-date-unix true 设置 DateTime 输出时间戳
Accept application/json 指定输出 json 格式的 json 字符串格式

适用范围定义

在一定程度上使 API 接入变得稍微复杂了一点点,但是能优化网络传输,或许我们可以考虑牺牲一点复杂度,按需索取来优化传输问题。

客户端 适合程度
移动端 非常适合
web 端 适合
服务端 跨语言,在不同规范的情况下适合接入,能解决模型不一致的问题,k8s 内走内网地址不需要考虑这个问题
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.6.26 180 a month ago
9.6.25 110 4 months ago
9.6.24 110 4 months ago
9.6.23 130 4 months ago
9.6.22 115 5 months ago
9.6.21 117 5 months ago
9.6.19 115 5 months ago
9.6.18 128 6 months ago
9.6.17 114 6 months ago
9.6.16 112 6 months ago
9.6.15 112 6 months ago
9.6.14 118 6 months ago
9.6.13 109 6 months ago
9.6.12 112 7 months ago
9.6.11 127 7 months ago
9.6.10 126 7 months ago
9.6.9 113 7 months ago
9.6.8 131 7 months ago
9.6.7 117 7 months ago
9.6.6 115 7 months ago
9.6.5 118 7 months ago
9.6.4 115 7 months ago
9.6.3 131 8 months ago
9.6.2 153 8 months ago
9.6.1 147 8 months ago
9.5.9 103 9 months ago
9.5.8 125 9 months ago
9.5.7 75 9 months ago
9.5.6 88 9 months ago
9.5.5 129 9 months ago
9.5.4 133 9 months ago
9.5.3 148 9 months ago
9.5.2 125 9 months ago
9.5.1 113 9 months ago
9.4.11 129 10 months ago
9.4.10 139 10 months ago
9.4.9 127 10 months ago
9.4.8 119 10 months ago
9.4.7 133 10 months ago
9.4.6 131 6/26/2024
9.4.5 125 6/25/2024
9.4.4 124 6/23/2024
9.4.3 169 6/21/2024
9.4.2 132 6/14/2024
9.4.1 127 6/14/2024
9.3.11 149 6/4/2024
9.3.10 147 6/4/2024
9.3.9 144 5/31/2024
9.3.8 172 5/28/2024
9.3.7 252 5/24/2024
9.3.6 201 5/23/2024
9.3.5 193 5/23/2024
9.3.4 177 5/22/2024
9.3.3 302 5/15/2024
9.3.2 157 5/15/2024
9.3.1 179 5/15/2024
9.2.19 160 5/14/2024
9.2.18 155 5/14/2024
9.2.17 148 5/14/2024
9.2.16 159 5/14/2024
9.2.15 177 5/13/2024
9.2.14 165 5/13/2024
9.2.13 157 5/13/2024
9.2.12 176 5/12/2024
9.2.11 192 5/11/2024
9.2.10 189 5/10/2024
9.2.9 216 5/9/2024
9.2.8 214 5/7/2024
9.2.7 183 5/7/2024
9.2.6 135 4/29/2024
9.2.5 157 4/25/2024
9.2.4 148 4/22/2024
9.2.3 162 4/19/2024
9.2.2 158 4/19/2024
9.2.1 169 4/17/2024
9.1.13 173 4/16/2024
9.1.12 210 4/16/2024
9.1.11 192 4/16/2024
9.1.10 170 4/14/2024
9.1.9 190 4/14/2024
9.1.8 162 4/12/2024
9.1.7 204 4/12/2024
9.1.6 170 4/12/2024
9.1.5 195 4/11/2024
9.1.4 239 4/11/2024
9.1.3 204 4/11/2024
9.1.2 212 4/10/2024
9.1.1 169 4/9/2024
8.11.12 187 4/9/2024
8.11.11 227 4/3/2024
8.11.10 234 3/29/2024
8.11.9 358 3/28/2024
8.11.8 367 3/26/2024
8.11.7 279 3/25/2024
8.11.6 416 3/21/2024
8.11.5 650 3/13/2024
8.11.4 435 3/10/2024
8.11.3 543 3/4/2024
8.11.2 395 3/4/2024
8.11.1 515 3/1/2024
8.10.14 518 2/21/2024
8.10.13 557 2/20/2024
8.10.12 490 2/20/2024
8.10.11 547 2/20/2024
8.10.10 440 2/20/2024
8.10.8 310 2/20/2024
8.10.7 462 2/18/2024
8.10.6 396 2/18/2024
8.10.5 710 2/6/2024
8.10.4 495 2/6/2024
8.10.3 493 2/4/2024
8.10.2 502 2/4/2024
8.10.1 435 2/4/2024
8.9.9 480 2/3/2024
8.9.8 468 2/3/2024
8.9.7 611 1/26/2024
8.9.6 473 1/26/2024
8.9.5 512 1/25/2024
8.9.4 527 1/25/2024
8.9.3 633 1/24/2024
8.9.2 518 1/23/2024
8.9.1 616 1/23/2024
8.9.0 395 1/23/2024
8.8.9 341 1/23/2024
8.8.8 566 1/22/2024
8.8.7 577 1/22/2024
8.8.6 357 1/22/2024
8.8.5 505 1/22/2024
8.8.4 462 1/22/2024
8.8.3 467 1/22/2024
8.8.2 435 1/20/2024
8.8.1 423 1/20/2024
8.8.0 433 1/20/2024
8.7.9 435 1/20/2024
8.7.8 403 1/20/2024
8.7.7 451 1/19/2024
8.7.6 384 1/19/2024
8.7.5 444 1/19/2024
8.7.4 511 1/19/2024
8.7.3 464 1/19/2024
8.7.2 527 1/19/2024
8.7.1 621 1/19/2024
8.7.0 453 1/18/2024
8.6.9 362 1/18/2024
8.6.8 533 1/18/2024
8.6.7 495 1/18/2024
8.6.6 382 1/18/2024
8.6.5 453 1/18/2024
8.6.4 464 1/17/2024
8.6.3 492 1/17/2024
8.6.2 439 1/17/2024
8.6.1 648 1/16/2024
8.6.0 453 1/16/2024
8.5.9 342 1/16/2024
8.5.8 468 1/15/2024
8.5.7 452 1/15/2024
8.5.6 526 1/15/2024
8.5.5 537 1/14/2024
8.5.4 347 1/14/2024
8.5.3 517 1/13/2024
8.5.2 417 1/13/2024
8.5.1 435 1/13/2024
8.5.0 418 1/12/2024
8.4.9 424 1/11/2024
8.4.8 504 1/11/2024
8.4.7 509 1/10/2024
8.4.6 512 1/10/2024
8.4.5 429 1/10/2024
8.4.4 568 1/9/2024
8.4.3 596 1/8/2024
8.4.2 604 1/8/2024
8.4.1 565 1/8/2024
8.4.0 437 1/8/2024
8.3.9 541 1/8/2024
8.3.8 462 1/8/2024
8.3.7 555 1/8/2024
8.3.6 592 1/6/2024
8.3.5 550 1/5/2024
8.3.4 512 1/5/2024
8.3.3 496 1/5/2024
8.3.2 456 1/5/2024
8.3.1 563 1/5/2024
8.3.0 334 1/5/2024
8.2.9 611 1/5/2024
8.2.8 459 1/4/2024
8.2.7 406 1/4/2024
8.2.6 459 1/4/2024
8.2.5 613 1/4/2024
8.2.4 445 1/3/2024
8.2.3 502 1/3/2024
8.2.2 495 1/3/2024
8.2.1 472 1/3/2024
8.2.0 558 1/2/2024
8.1.9 433 1/2/2024
8.1.8 703 12/25/2023
8.1.7 760 12/18/2023
8.1.6 655 12/15/2023
8.1.5 597 12/14/2023
8.1.4 536 12/14/2023
8.1.3 559 12/14/2023
8.1.2 542 12/14/2023
8.1.1 531 12/14/2023
8.1.0 519 12/13/2023
8.0.9 505 12/13/2023
8.0.8 635 12/13/2023
8.0.7 582 12/13/2023
8.0.6 560 12/12/2023
8.0.5 550 12/12/2023
8.0.4 545 12/11/2023
8.0.3 629 12/7/2023
8.0.2 541 12/6/2023
8.0.1 755 12/5/2023
8.0.0 690 12/5/2023
7.9.9 615 12/5/2023
7.9.8 571 12/5/2023
7.9.7 532 12/4/2023
7.9.6 503 12/4/2023
7.9.5 547 12/1/2023
7.9.4 739 11/24/2023
7.9.3 508 11/24/2023
7.9.2 507 11/23/2023
7.9.1 772 11/17/2023
7.9.0 564 11/17/2023
7.8.9 497 11/17/2023
7.8.8 609 11/16/2023
7.8.6 526 11/16/2023
7.8.5 655 11/16/2023
7.8.4 472 11/15/2023
7.8.3 588 11/14/2023
7.8.2 530 11/10/2023
7.8.1 665 11/10/2023
7.8.0 536 11/10/2023
7.7.9 665 11/9/2023
7.7.8 500 11/9/2023
7.7.7 489 11/8/2023
7.7.6 622 11/8/2023
7.7.5 508 11/7/2023
7.7.4 464 11/7/2023
7.7.3 551 11/7/2023
7.7.2 580 11/7/2023
7.7.1 711 11/7/2023
7.7.0 658 11/3/2023
7.6.9 559 11/3/2023
7.6.8 589 11/3/2023
7.6.7 615 11/3/2023
7.6.6 613 11/2/2023
7.6.5 609 10/31/2023
7.6.4 632 10/31/2023
7.6.3 676 10/30/2023
7.6.2 813 10/27/2023
7.6.1 752 10/27/2023
7.6.0 665 10/27/2023
7.5.9 714 10/27/2023
7.5.8 672 10/27/2023
7.5.7 723 10/26/2023
7.5.6 618 10/26/2023
7.5.5 601 10/26/2023
7.5.4 558 10/26/2023
7.5.3 573 10/25/2023
7.5.2 595 10/25/2023
7.5.1 534 10/25/2023
7.5.0 681 10/24/2023
7.4.9 629 10/24/2023
7.4.8 635 10/24/2023
7.4.7 566 10/23/2023
7.4.6 738 10/20/2023
7.4.5 631 10/20/2023
7.4.4 831 10/18/2023
7.4.3 941 10/9/2023
7.4.2 662 10/8/2023
7.4.1 627 10/7/2023
7.4.0 590 9/15/2023
7.3.9 850 9/15/2023
7.3.8 573 9/14/2023
7.3.7 521 9/14/2023
7.3.6 673 9/14/2023
7.3.5 659 9/13/2023
7.3.4 624 9/13/2023
7.3.3 782 9/13/2023
7.3.2 649 9/12/2023
7.3.1 737 9/12/2023
7.3.0 637 9/12/2023
7.2.9 650 9/7/2023
7.2.8 622 9/7/2023
7.2.7 714 9/6/2023
7.2.6 604 9/6/2023
7.2.5 697 9/6/2023
7.2.4 724 8/31/2023
7.2.3 709 8/31/2023
7.2.2 709 8/30/2023
7.2.1 755 8/30/2023
7.2.0 721 8/30/2023
7.1.9 618 8/29/2023
7.1.8 732 8/29/2023
7.1.7 843 8/29/2023
7.1.6 599 8/29/2023
7.1.5 817 8/28/2023
7.1.4 783 8/28/2023
7.1.3 758 8/28/2023
7.1.2 729 8/25/2023
7.1.1 763 8/25/2023
7.1.0 751 8/25/2023
7.0.9 777 8/25/2023
7.0.8 754 8/24/2023
7.0.7 717 8/24/2023
7.0.6 683 8/24/2023
7.0.5 872 8/24/2023
7.0.4 618 8/23/2023
7.0.3 697 8/23/2023
7.0.2 513 8/23/2023
7.0.1 728 8/23/2023
7.0.0 791 8/22/2023
6.9.18 636 8/22/2023
6.9.17 712 8/22/2023
6.9.16 680 8/22/2023
6.9.15 758 8/22/2023
6.9.14 740 8/22/2023
6.9.13 583 8/22/2023
6.9.12 636 8/20/2023
6.9.11 812 8/19/2023
6.9.10 705 8/19/2023
6.9.9 719 8/19/2023