XUCore.Template.EasyFreeSql 8.7.7

There is a newer version of this package available.
See the version list below for details.
dotnet new install XUCore.Template.EasyFreeSql::8.7.7                
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.25 98 2 months ago
9.6.24 100 2 months ago
9.6.23 120 3 months ago
9.6.22 107 3 months ago
9.6.21 110 4 months ago
9.6.19 107 4 months ago
9.6.18 120 4 months ago
9.6.17 104 4 months ago
9.6.16 105 4 months ago
9.6.15 105 4 months ago
9.6.14 108 4 months ago
9.6.13 101 4 months ago
9.6.12 106 5 months ago
9.6.11 119 5 months ago
9.6.10 116 5 months ago
9.6.9 103 5 months ago
9.6.8 123 5 months ago
9.6.7 108 5 months ago
9.6.6 104 5 months ago
9.6.5 109 6 months ago
9.6.4 108 6 months ago
9.6.3 122 6 months ago
9.6.2 145 6 months ago
9.6.1 141 7 months ago
9.5.9 96 7 months ago
9.5.8 118 7 months ago
9.5.7 67 7 months ago
9.5.6 81 7 months ago
9.5.5 121 7 months ago
9.5.4 126 7 months ago
9.5.3 142 7 months ago
9.5.2 118 7 months ago
9.5.1 107 7 months ago
9.4.11 121 8 months ago
9.4.10 132 8 months ago
9.4.9 120 8 months ago
9.4.8 113 8 months ago
9.4.7 126 8 months ago
9.4.6 124 8 months ago
9.4.5 118 8 months ago
9.4.4 114 8 months ago
9.4.3 161 8 months ago
9.4.2 125 9 months ago
9.4.1 121 9 months ago
9.3.11 143 9 months ago
9.3.10 140 9 months ago
9.3.9 139 9 months ago
9.3.8 162 9 months ago
9.3.7 246 9 months ago
9.3.6 191 9 months ago
9.3.5 166 9 months ago
9.3.4 169 9 months ago
9.3.3 292 10 months ago
9.3.2 150 10 months ago
9.3.1 170 10 months ago
9.2.19 153 10 months ago
9.2.18 147 10 months ago
9.2.17 141 10 months ago
9.2.16 152 10 months ago
9.2.15 169 10 months ago
9.2.14 157 10 months ago
9.2.13 150 10 months ago
9.2.12 168 10 months ago
9.2.11 184 10 months ago
9.2.10 183 10 months ago
9.2.9 207 10 months ago
9.2.8 208 10 months ago
9.2.7 178 10 months ago
9.2.6 130 4/29/2024
9.2.5 152 4/25/2024
9.2.4 141 4/22/2024
9.2.3 155 4/19/2024
9.2.2 153 4/19/2024
9.2.1 162 4/17/2024
9.1.13 168 4/16/2024
9.1.12 202 4/16/2024
9.1.11 186 4/16/2024
9.1.10 166 4/14/2024
9.1.9 185 4/14/2024
9.1.8 157 4/12/2024
9.1.7 197 4/12/2024
9.1.6 164 4/12/2024
9.1.5 189 4/11/2024
9.1.4 234 4/11/2024
9.1.3 199 4/11/2024
9.1.2 206 4/10/2024
9.1.1 164 4/9/2024
8.11.12 180 4/9/2024
8.11.11 222 4/3/2024
8.11.10 228 3/29/2024
8.11.9 353 3/28/2024
8.11.8 360 3/26/2024
8.11.7 273 3/25/2024
8.11.6 410 3/21/2024
8.11.5 644 3/13/2024
8.11.4 428 3/10/2024
8.11.3 538 3/4/2024
8.11.2 388 3/4/2024
8.11.1 509 3/1/2024
8.10.14 510 2/21/2024
8.10.13 551 2/20/2024
8.10.12 485 2/20/2024
8.10.11 543 2/20/2024
8.10.10 434 2/20/2024
8.10.8 304 2/20/2024
8.10.7 457 2/18/2024
8.10.6 390 2/18/2024
8.10.5 704 2/6/2024
8.10.4 490 2/6/2024
8.10.3 489 2/4/2024
8.10.2 497 2/4/2024
8.10.1 430 2/4/2024
8.9.9 475 2/3/2024
8.9.8 463 2/3/2024
8.9.7 606 1/26/2024
8.9.6 468 1/26/2024
8.9.5 506 1/25/2024
8.9.4 522 1/25/2024
8.9.3 627 1/24/2024
8.9.2 512 1/23/2024
8.9.1 610 1/23/2024
8.9.0 389 1/23/2024
8.8.9 335 1/23/2024
8.8.8 560 1/22/2024
8.8.7 563 1/22/2024
8.8.6 349 1/22/2024
8.8.5 499 1/22/2024
8.8.4 456 1/22/2024
8.8.3 461 1/22/2024
8.8.2 430 1/20/2024
8.8.1 418 1/20/2024
8.8.0 427 1/20/2024
8.7.9 429 1/20/2024
8.7.8 397 1/20/2024
8.7.7 445 1/19/2024
8.7.6 381 1/19/2024
8.7.5 438 1/19/2024
8.7.4 506 1/19/2024
8.7.3 459 1/19/2024
8.7.2 521 1/19/2024
8.7.1 616 1/19/2024
8.7.0 447 1/18/2024
8.6.9 357 1/18/2024
8.6.8 527 1/18/2024
8.6.7 490 1/18/2024
8.6.6 377 1/18/2024
8.6.5 447 1/18/2024
8.6.4 460 1/17/2024
8.6.3 488 1/17/2024
8.6.2 434 1/17/2024
8.6.1 642 1/16/2024
8.6.0 448 1/16/2024
8.5.9 336 1/16/2024
8.5.8 461 1/15/2024
8.5.7 443 1/15/2024
8.5.6 518 1/15/2024
8.5.5 532 1/14/2024
8.5.4 343 1/14/2024
8.5.3 512 1/13/2024
8.5.2 411 1/13/2024
8.5.1 429 1/13/2024
8.5.0 413 1/12/2024
8.4.9 420 1/11/2024
8.4.8 498 1/11/2024
8.4.7 503 1/10/2024
8.4.6 504 1/10/2024
8.4.5 423 1/10/2024
8.4.4 561 1/9/2024
8.4.3 591 1/8/2024
8.4.2 597 1/8/2024
8.4.1 560 1/8/2024
8.4.0 432 1/8/2024
8.3.9 536 1/8/2024
8.3.8 457 1/8/2024
8.3.7 550 1/8/2024
8.3.6 587 1/6/2024
8.3.5 544 1/5/2024
8.3.4 505 1/5/2024
8.3.3 491 1/5/2024
8.3.2 448 1/5/2024
8.3.1 558 1/5/2024
8.3.0 328 1/5/2024
8.2.9 605 1/5/2024
8.2.8 454 1/4/2024
8.2.7 400 1/4/2024
8.2.6 453 1/4/2024
8.2.5 607 1/4/2024
8.2.4 437 1/3/2024
8.2.3 495 1/3/2024
8.2.2 487 1/3/2024
8.2.1 465 1/3/2024
8.2.0 550 1/2/2024
8.1.9 426 1/2/2024
8.1.8 696 12/25/2023
8.1.7 738 12/18/2023
8.1.6 649 12/15/2023
8.1.5 591 12/14/2023
8.1.4 519 12/14/2023
8.1.3 553 12/14/2023
8.1.2 536 12/14/2023
8.1.1 525 12/14/2023
8.1.0 513 12/13/2023
8.0.9 499 12/13/2023
8.0.8 627 12/13/2023
8.0.7 577 12/13/2023
8.0.6 554 12/12/2023
8.0.5 544 12/12/2023
8.0.4 539 12/11/2023
8.0.3 623 12/7/2023
8.0.2 540 12/6/2023
8.0.1 752 12/5/2023
8.0.0 686 12/5/2023
7.9.9 613 12/5/2023
7.9.8 569 12/5/2023
7.9.7 531 12/4/2023
7.9.6 501 12/4/2023
7.9.5 545 12/1/2023
7.9.4 737 11/24/2023
7.9.3 507 11/24/2023
7.9.2 505 11/23/2023
7.9.1 771 11/17/2023
7.9.0 562 11/17/2023
7.8.9 494 11/17/2023
7.8.8 607 11/16/2023
7.8.6 523 11/16/2023
7.8.5 650 11/16/2023
7.8.4 471 11/15/2023
7.8.3 583 11/14/2023
7.8.2 529 11/10/2023
7.8.1 664 11/10/2023
7.8.0 533 11/10/2023
7.7.9 663 11/9/2023
7.7.8 498 11/9/2023
7.7.7 488 11/8/2023
7.7.6 619 11/8/2023
7.7.5 507 11/7/2023
7.7.4 463 11/7/2023
7.7.3 550 11/7/2023
7.7.2 579 11/7/2023
7.7.1 710 11/7/2023
7.7.0 657 11/3/2023
7.6.9 557 11/3/2023
7.6.8 571 11/3/2023
7.6.7 614 11/3/2023
7.6.6 612 11/2/2023
7.6.5 608 10/31/2023
7.6.4 631 10/31/2023
7.6.3 674 10/30/2023
7.6.2 810 10/27/2023
7.6.1 742 10/27/2023
7.6.0 663 10/27/2023
7.5.9 713 10/27/2023
7.5.8 670 10/27/2023
7.5.7 721 10/26/2023
7.5.6 615 10/26/2023
7.5.5 598 10/26/2023
7.5.4 554 10/26/2023
7.5.3 571 10/25/2023
7.5.2 593 10/25/2023
7.5.1 532 10/25/2023
7.5.0 679 10/24/2023
7.4.9 627 10/24/2023
7.4.8 633 10/24/2023
7.4.7 564 10/23/2023
7.4.6 737 10/20/2023
7.4.5 630 10/20/2023
7.4.4 827 10/18/2023
7.4.3 939 10/9/2023
7.4.2 660 10/8/2023
7.4.1 625 10/7/2023
7.4.0 588 9/15/2023
7.3.9 848 9/15/2023
7.3.8 571 9/14/2023
7.3.7 519 9/14/2023
7.3.6 673 9/14/2023
7.3.5 657 9/13/2023
7.3.4 620 9/13/2023
7.3.3 781 9/13/2023
7.3.2 645 9/12/2023
7.3.1 734 9/12/2023
7.3.0 635 9/12/2023
7.2.9 649 9/7/2023
7.2.8 619 9/7/2023
7.2.7 713 9/6/2023
7.2.6 603 9/6/2023
7.2.5 694 9/6/2023
7.2.4 722 8/31/2023
7.2.3 707 8/31/2023
7.2.2 708 8/30/2023
7.2.1 752 8/30/2023
7.2.0 720 8/30/2023
7.1.9 616 8/29/2023
7.1.8 731 8/29/2023
7.1.7 842 8/29/2023
7.1.6 598 8/29/2023
7.1.5 815 8/28/2023
7.1.4 778 8/28/2023
7.1.3 756 8/28/2023
7.1.2 726 8/25/2023
7.1.1 759 8/25/2023
7.1.0 747 8/25/2023
7.0.9 774 8/25/2023
7.0.8 750 8/24/2023
7.0.7 716 8/24/2023
7.0.6 682 8/24/2023
7.0.5 870 8/24/2023
7.0.4 616 8/23/2023
7.0.3 695 8/23/2023
7.0.2 511 8/23/2023
7.0.1 726 8/23/2023
7.0.0 789 8/22/2023
6.9.18 635 8/22/2023
6.9.17 711 8/22/2023
6.9.16 679 8/22/2023
6.9.15 756 8/22/2023
6.9.14 738 8/22/2023
6.9.13 581 8/22/2023
6.9.12 634 8/20/2023
6.9.11 809 8/19/2023
6.9.10 704 8/19/2023
6.9.9 717 8/19/2023