XUCore.Template.FreeSql 9.5.1

There is a newer version of this package available.
See the version list below for details.
dotnet new install XUCore.Template.FreeSql::9.5.1                
This package contains a .NET Template Package you can call from the shell/command line.

XUCore.Template.FreeSql

XUCore.Template.FreeSql

基于 FreeSql 的精简分层快速开发项目模板,生成 WebApi 项目

使用模板

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

本地安装模板步骤:

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


dotnet new -u xfreesql

然后安装指定版本:


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

创建项目

切换到指定创建的目录。

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

那么先切换到该目录


cd E:\demo

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


dotnet new xfreesql -n MyTest -o .

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

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.24 94 15 days ago
9.6.23 94 a month ago
9.6.22 107 a month ago
9.6.21 107 2 months ago
9.6.19 99 2 months ago
9.6.18 100 2 months ago
9.6.17 102 2 months ago
9.6.16 95 2 months ago
9.6.15 94 2 months ago
9.6.14 104 3 months ago
9.6.13 101 3 months ago
9.6.12 118 3 months ago
9.6.11 112 4 months ago
9.6.10 106 4 months ago
9.6.9 96 4 months ago
9.6.8 108 4 months ago
9.6.7 95 4 months ago
9.6.6 93 4 months ago
9.6.5 116 4 months ago
9.6.4 128 4 months ago
9.6.3 138 5 months ago
9.6.2 139 5 months ago
9.6.1 141 5 months ago
9.5.9 96 5 months ago
9.5.8 97 5 months ago
9.5.7 93 5 months ago
9.5.6 90 6 months ago
9.5.5 111 6 months ago
9.5.4 112 6 months ago
9.5.3 110 6 months ago
9.5.2 105 6 months ago
9.5.1 119 6 months ago
9.4.11 108 6 months ago
9.4.10 99 6 months ago
9.4.9 129 6 months ago
9.4.8 119 6 months ago
9.4.7 127 6 months ago
9.4.6 120 7 months ago
9.4.5 118 7 months ago
9.4.4 125 7 months ago
9.4.3 116 7 months ago
9.4.2 121 7 months ago
9.4.1 113 7 months ago
9.3.11 116 7 months ago
9.3.10 120 7 months ago
9.3.9 126 7 months ago
9.3.8 152 7 months ago
9.3.7 220 8 months ago
9.3.6 130 8 months ago
9.3.5 137 8 months ago
9.3.4 155 8 months ago
9.3.3 278 8 months ago
9.3.2 147 8 months ago
9.3.1 135 8 months ago
9.2.19 140 8 months ago
9.2.18 123 8 months ago
9.2.17 117 8 months ago
9.2.16 141 8 months ago
9.2.15 143 8 months ago
9.2.14 162 8 months ago
9.2.13 107 8 months ago
9.2.12 130 8 months ago
9.2.11 193 8 months ago
9.2.10 138 8 months ago
9.2.9 154 8 months ago
9.2.8 188 8 months ago
9.2.7 159 8 months ago
9.2.6 113 8 months ago
9.2.5 129 9 months ago
9.2.4 142 9 months ago
9.2.3 119 9 months ago
9.2.2 131 9 months ago
9.2.1 123 9 months ago
9.1.13 152 9 months ago
9.1.12 125 9 months ago
9.1.11 161 9 months ago
9.1.10 167 9 months ago
9.1.9 153 9 months ago
9.1.8 162 9 months ago
9.1.7 133 9 months ago
9.1.6 169 9 months ago
9.1.5 174 9 months ago
9.1.4 137 9 months ago
9.1.3 145 9 months ago
9.1.2 141 9 months ago
9.1.1 212 9 months ago
8.11.12 142 9 months ago
8.11.11 164 9 months ago
8.11.10 174 9 months ago
8.11.9 221 9 months ago
8.11.8 229 10 months ago
8.11.7 303 10 months ago
8.11.6 364 10 months ago
8.11.5 458 10 months ago
8.11.4 312 3/10/2024
8.11.3 446 3/4/2024
8.11.2 342 3/4/2024
8.11.1 376 3/1/2024
8.10.14 580 2/21/2024
8.10.13 338 2/20/2024
8.10.12 386 2/20/2024
8.10.11 303 2/20/2024
8.10.10 337 2/20/2024
8.10.8 463 2/20/2024
8.10.7 353 2/18/2024
8.10.6 341 2/18/2024
8.10.5 707 2/6/2024
8.10.4 388 2/6/2024
8.10.3 449 2/4/2024
8.10.2 394 2/4/2024
8.10.1 572 2/4/2024
8.9.9 394 2/3/2024
8.9.8 341 2/3/2024
8.9.7 605 1/26/2024
8.9.6 353 1/26/2024
8.9.5 482 1/25/2024
8.9.4 421 1/25/2024
8.9.3 614 1/24/2024
8.9.2 507 1/23/2024
8.9.1 328 1/23/2024
8.9.0 408 1/23/2024
8.8.9 518 1/23/2024
8.8.8 501 1/22/2024
8.8.7 584 1/22/2024
8.8.6 406 1/22/2024
8.8.5 405 1/22/2024
8.8.4 340 1/22/2024
8.8.3 434 1/22/2024
8.8.2 465 1/20/2024
8.8.1 493 1/20/2024
8.8.0 460 1/20/2024
8.7.9 444 1/20/2024
8.7.8 520 1/20/2024
8.7.7 472 1/19/2024
8.7.6 478 1/19/2024
8.7.5 449 1/19/2024
8.7.4 467 1/19/2024
8.7.3 378 1/19/2024
8.7.2 409 1/19/2024
8.7.1 499 1/19/2024
8.7.0 430 1/18/2024
8.6.9 466 1/18/2024
8.6.8 403 1/18/2024
8.6.7 418 1/18/2024
8.6.6 477 1/18/2024
8.6.5 445 1/18/2024
8.6.4 443 1/17/2024
8.6.3 449 1/17/2024
8.6.2 533 1/17/2024
8.6.1 466 1/16/2024
8.6.0 481 1/16/2024
8.5.9 477 1/16/2024
8.5.8 454 1/15/2024
8.5.7 498 1/15/2024
8.5.6 600 1/15/2024
8.5.5 532 1/14/2024
8.5.4 524 1/14/2024
8.5.3 527 1/13/2024
8.5.2 453 1/13/2024
8.5.1 491 1/13/2024
8.5.0 521 1/12/2024
8.4.9 484 1/11/2024
8.4.8 591 1/11/2024
8.4.7 539 1/10/2024
8.4.6 627 1/10/2024
8.4.5 442 1/10/2024
8.4.4 548 1/9/2024
8.4.3 601 1/8/2024
8.4.2 604 1/8/2024
8.4.1 554 1/8/2024
8.4.0 417 1/8/2024
8.3.9 480 1/8/2024
8.3.8 498 1/8/2024
8.3.7 497 1/8/2024
8.3.6 610 1/6/2024
8.3.5 493 1/5/2024
8.3.4 539 1/5/2024
8.3.3 478 1/5/2024
8.3.2 438 1/5/2024
8.3.1 626 1/5/2024
8.3.0 475 1/5/2024
8.2.9 540 1/5/2024
8.2.8 642 1/4/2024
8.2.7 581 1/4/2024
8.2.6 501 1/4/2024
8.2.5 441 1/4/2024
8.2.4 548 1/3/2024
8.2.3 500 1/3/2024
8.2.2 661 1/3/2024
8.2.1 521 1/3/2024
8.2.0 496 1/2/2024
8.1.9 439 1/2/2024
8.1.8 771 12/25/2023
8.1.7 954 12/18/2023
8.1.6 686 12/15/2023
8.1.5 640 12/14/2023
8.1.4 706 12/14/2023
8.1.3 642 12/14/2023
8.1.2 665 12/14/2023
8.1.1 644 12/14/2023
8.1.0 722 12/13/2023
8.0.9 599 12/13/2023
8.0.8 524 12/13/2023
8.0.7 600 12/13/2023
8.0.6 778 12/12/2023
8.0.5 785 12/12/2023
8.0.4 808 12/11/2023
8.0.3 778 12/7/2023
8.0.2 675 12/6/2023
8.0.1 627 12/5/2023
8.0.0 522 12/5/2023
7.9.9 861 12/5/2023
7.9.8 753 12/5/2023
7.9.7 737 12/4/2023
7.9.6 587 12/4/2023
7.9.5 647 12/1/2023
7.9.4 926 11/24/2023
7.9.3 631 11/24/2023
7.9.2 800 11/23/2023
7.9.1 799 11/17/2023
7.9.0 627 11/17/2023
7.8.9 623 11/17/2023
7.8.8 684 11/16/2023
7.8.7 540 11/16/2023
7.8.6 670 11/16/2023
7.8.5 640 11/16/2023
7.8.4 589 11/15/2023
7.8.3 528 11/14/2023
7.8.2 632 11/10/2023
7.8.1 731 11/10/2023
7.8.0 698 11/10/2023
7.7.9 608 11/9/2023
7.7.8 570 11/9/2023
7.7.7 650 11/8/2023
7.7.6 605 11/8/2023
7.7.5 697 11/7/2023
7.7.4 656 11/7/2023
7.7.3 550 11/7/2023
7.7.2 603 11/7/2023
7.7.1 641 11/7/2023
7.7.0 754 11/3/2023
7.6.9 699 11/3/2023
7.6.8 771 11/3/2023
7.6.7 638 11/3/2023
7.6.6 728 11/2/2023
7.6.5 787 10/31/2023
7.6.4 653 10/31/2023
7.6.3 637 10/30/2023
7.6.2 761 10/27/2023
7.6.1 686 10/27/2023
7.6.0 701 10/27/2023
7.5.9 847 10/27/2023
7.5.8 721 10/27/2023
7.5.7 700 10/26/2023
7.5.6 736 10/26/2023
7.5.5 759 10/26/2023
7.5.4 552 10/26/2023
7.5.3 760 10/25/2023
7.5.2 683 10/25/2023
7.5.1 792 10/25/2023
7.5.0 814 10/24/2023
7.4.9 704 10/24/2023
7.4.8 800 10/24/2023
7.4.7 722 10/23/2023
7.4.6 808 10/20/2023
7.4.5 804 10/20/2023
7.4.4 647 10/18/2023
7.4.3 973 10/9/2023
7.4.2 578 10/8/2023
7.4.1 890 10/7/2023
7.4.0 795 9/15/2023
7.3.9 689 9/15/2023
7.3.8 709 9/14/2023
7.3.7 632 9/14/2023
7.3.6 761 9/14/2023
7.3.5 870 9/13/2023
7.3.4 732 9/13/2023
7.3.3 704 9/13/2023
7.3.2 609 9/12/2023
7.3.1 778 9/12/2023
7.3.0 831 9/12/2023
7.2.9 838 9/7/2023
7.2.8 768 9/7/2023
7.2.7 631 9/6/2023
7.2.6 768 9/6/2023
7.2.5 835 9/6/2023
7.2.4 783 8/31/2023
7.2.3 807 8/31/2023
7.2.2 702 8/30/2023
7.2.1 765 8/30/2023
7.2.0 818 8/30/2023
7.1.9 812 8/29/2023
7.1.8 745 8/29/2023
7.1.7 756 8/29/2023
7.1.6 690 8/29/2023
7.1.5 931 8/28/2023
7.1.4 854 8/28/2023
7.1.3 701 8/28/2023
7.1.2 822 8/25/2023
7.1.1 838 8/25/2023
7.1.0 731 8/25/2023
7.0.9 759 8/25/2023
7.0.8 579 8/24/2023
7.0.7 697 8/24/2023
7.0.6 800 8/24/2023
7.0.5 847 8/24/2023
7.0.4 726 8/23/2023
6.9.18 952 8/22/2023
6.9.17 863 8/22/2023
6.9.16 782 8/22/2023
6.9.15 810 8/22/2023
6.9.14 880 8/22/2023
6.9.13 784 8/22/2023
6.9.12 778 8/20/2023
6.9.11 786 8/19/2023
6.9.10 677 8/19/2023
6.9.9 894 8/19/2023