直接上代码
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
List<TestModel> testList = new List<TestModel>(); testList.Add(new TestModel { Id = 1, Name = "A" }); testList.Add(new TestModel { Id = 2, Name = "B" }); testList.Add(new TestModel { Id = 3, Name = "C" }); List<dynamic> test = new List<dynamic>(); foreach (var item in testList) { dynamic dobj = new System.Dynamic.ExpandoObject(); var dic = (IDictionary<string, object>)dobj; var t = item.GetType(); var properties = t.GetProperties(); // 循环赋值原Model中的值 foreach (var propertyInfo in properties) { var propertyName = propertyInfo.Name; dic[propertyName] = propertyInfo.GetValue(item); } // 动态扩展属性 dic["Age"] = 3; test.Add(dic); } |
示例Model
|
1 2 3 4 5 |
public class TestModel { public int Id { get; set; } public string Name { get; set; } } |
1.将json对象转化为json字符串,再判断该字符串是否为"{}" var data = {}; var b = (JSON.stringify(data) == "{}"); alert(b);//true 2.for in 循环判断 var obj = {}; var b = function() { for(var key in obj) { return false; } return true; } alert(b());//true 3.jquery的isEmptyObject方法 此方法是jquery将2方法(for in)进行封装,使用时需要依赖jquery var data = {}; var b = $.isEmptyObject(data); alert(b);//true 4.Object.getOwnPropertyNames()方法 此方法是使用Object对象的getOwnPropertyNames方法,获取到对象中的属性名,存到一个数组中,返回数组对象,我们可以通过判断数组的length来判断此对象是否为空 注意:此方法不兼容ie8,其余浏览器没有测试 var data = {}; var arr = Object.getOwnPropertyNames(data); // Object.keys(objTest).length alert(arr.length == 0);//true 5.使用ES6的Object.keys()方法 与4方法类似,是ES6的新方法, 返回值也是对象中属性名组成的数组 var data = {}; var arr = Object.keys(data); alert(arr.length == 0);//true from:https://www.cnblogs.com/jpfss/p/9105119.html
View Details1.服务配置文件
|
1 2 |
cd /etc/systemd/system touch your_service_name.service |
|
1 2 3 4 5 6 |
[Unit] Description=zaomianbao [Service] ExecStart= /your_java_path/bin/java -jar /your_app_path/your_app_name.jar [Install] WantedBy=multi-user.target |
2.启动服务
|
1 |
systemctl start your_service_name.service |
参考: https://blog.csdn.net/weixin_37490221/article/details/80758276
View Details直接用java -jar xxx.jar,当退出或关闭shell时,程序就会停止掉。以下方法可让jar运行后一直在后台运行。 方法一 java -jar xxx.jar & 说明: 在末尾加入 & 符号 方法二 (1)执行java -jar xxx.jar后 (2)ctrl+z 退出到控制台,执行 bg (3)exit 完成以上3步,退出SHELL后,jar服务一直在后台运行。 方法三 nohup java -jar xxxx.jar & 将java -jar xxxx.jar 加入 nohup &中间,也可以实现 from:https://www.cnblogs.com/zsg88/p/9473843.html
View Detailswin10系统支持默认编码修改.。 好处: 1.解决由utf8引起的cmd,powershell等乱码问题 2.Visual Studio 2017(其他版本没试过) 新建文件则默认为utf8 3.其他 可能的坏处: 上古版本的第三方应用软件可能会出现乱码。 由于此设置,微软官方特别说明为【beta版】(截至时间2018年10月3日),可能会引起其他未知问题,请充分考虑后再决定是否设置。 工具/原料 win10系统 方法/步骤 在小娜中搜索地区,最佳匹配中会显示【更改国家或地区】的系统设置,双击打开。 在打开的设置中点击右上角的【管理语言设置】。 然后会打开一个【区域】的窗口设置,然后点击左上角的【管理】标签。 标签切换以后,点击【更改系统区域设置】。这个需要管理员权限才能操作。 然后回打开一个【区域设置】的小窗口,有个【beta版:使用Unicode UTF-8 提供全球语言支持】的选项,打上勾,点击确定。 然后会出现一个提示【现在重新启动】的窗口,点击【现在重新启动】按钮即可。 from:https://jingyan.baidu.com/article/25648fc1471e6a9191fd002e.html
View Details一般情况WebApi都是跨域请求,没有设置跨域一般会报以下错误
|
1 |
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:48057' is therefore not allowed access. |
ASP.net Core 跨域有两种,全局和区域 全局跨域: 打开Startup.cs文件.在ConfigureServices方法中添加以下代码 1.配置跨域处理,允许所有来源:
|
1 2 3 4 5 |
//配置跨域处理,允许所有来源: services.AddCors(options => options.AddPolicy("自定义的跨域策略名称", p => p.AllowAnyOrigin()) ); |
2.允许一个或多个具体来源:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
//允许一个或多个具体来源: services.AddCors(options => { // Policy 名稱 CorsPolicy 是自訂的,可以自己改 options.AddPolicy("跨域规则的名称", policy => { // 設定允許跨域的來源,有多個的話可以用 `,` 隔開 policy.WithOrigins("http://localhost:3000","http://127.0.0.1") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); |
以上两种按需求选择一种即可. Configure方法中添加以下代码
|
1 2 |
app.UseCors("自定义的跨域策略名称");//放到host之后【光子:20201021】 app.UseMvc(); |
局部跨域第一种用法: 1.ConfigureServices方法不变,删去Configure中的app.UseCors()方法 2.在Controller顶部或者Action方法顶部加上[EnableCors("自定义的跨域策略名称")]特性,例如
|
1 2 3 |
[EnableCors("自定义的跨域策略名称")] [Route("api/[controller]")] public class ContactController : Controller |
以上就可实现指定某个controller或者action跨域 禁止跨域: 禁止跨域在Controller或者Action加上[DisableCors]特性即可禁止跨域
|
1 2 3 4 5 6 |
[HttpGet("{id}")] [DisableCors] public string Get(int id) { return "value"; } |
参考: https://blog.johnwu.cc/article/asp-net-core-cors.html?from=singlemessage&isappinstalled=0 https://docs.microsoft.com/en-us/aspnet/core/security/cors http://www.cnblogs.com/tianma3798/p/6920704.html from:https://www.cnblogs.com/xiaoliangge/p/7650465.html
View DetailsDocker CE 镜像源站 使用官方安装脚本自动安装 (仅适用于公网环境)
|
1 |
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun |
手动安装帮助 (阿里云ECS可以通过内网安装,见注释部分内容) Ubuntu 14.04 16.04 (使用apt-get进行安装)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# step 1: 安装必要的一些系统工具 sudo apt-get update sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common # step 2: 安装GPG证书 curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - # Step 3: 写入软件源信息 sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" # Step 4: 更新并安装 Docker-CE sudo apt-get -y update sudo apt-get -y install docker-ce 注意:其他注意事项在下面的注释中 # 安装指定版本的Docker-CE: # Step 1: 查找Docker-CE的版本: # apt-cache madison docker-ce # docker-ce | 17.03.1~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages # docker-ce | 17.03.0~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages # Step 2: 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.1~ce-0~ubuntu-xenial) # sudo apt-get -y install docker-ce=[VERSION] # 通过经典网络、VPC网络内网安装时,用以下命令替换Step 2、Step 3中的命令 # 经典网络: # curl -fsSL http://mirrors.aliyuncs.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - # sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyuncs.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" # VPC网络: # curl -fsSL http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - # sudo add-apt-repository "deb [arch=amd64] http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" |
CentOS 7 (使用yum进行安装)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# step 1: 安装必要的一些系统工具 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 # Step 2: 添加软件源信息 sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # Step 3: 更新并安装 Docker-CE sudo yum makecache fast sudo yum -y install docker-ce # Step 4: 开启Docker服务 sudo service docker start 注意:其他注意事项在下面的注释中 # 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,你可以通过以下方式开启。同理可以开启各种测试版本等。 # vim /etc/yum.repos.d/docker-ce.repo # 将 [docker-ce-test] 下方的 enabled=0 修改为 enabled=1 # # 安装指定版本的Docker-CE: # Step 1: 查找Docker-CE的版本: # yum list docker-ce.x86_64 --showduplicates | sort -r # Loading mirror speeds from cached hostfile # Loaded plugins: branch, fastestmirror, langpacks # docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable # docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable # docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable # Available Packages # Step2 : 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.0.ce.1-1.el7.centos) # sudo yum -y install docker-ce-[VERSION] # 注意:在某些版本之后,docker-ce安装出现了其他依赖包,如果安装失败的话请关注错误信息。例如 docker-ce 17.03 之后,需要先安装 docker-ce-selinux。 # yum list docker-ce-selinux- --showduplicates | sort -r # sudo yum -y install docker-ce-selinux-[VERSION] # 通过经典网络、VPC网络内网安装时,用以下命令替换Step 2中的命令 # 经典网络: # sudo yum-config-manager --add-repo http://mirrors.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo # VPC网络: # sudo yum-config-manager --add-repo http://mirrors.could.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo |
安装校验
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
root@iZbp12adskpuoxodbkqzjfZ:$ docker version Client: Version: 17.03.0-ce API version: 1.26 Go version: go1.7.5 Git commit: 3a232c8 Built: Tue Feb 28 07:52:04 2017 OS/Arch: linux/amd64 Server: Version: 17.03.0-ce API version: 1.26 (minimum version 1.12) Go version: go1.7.5 Git commit: 3a232c8 Built: Tue Feb 28 07:52:04 2017 OS/Arch: linux/amd64 Experimental: false |
参考资料 其他关于旧版本Docker卸载以及测试开发版本Docker安装的帮助,可以参考官方文档的说明进行安装 from:https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.35501991rH2jyp
View Details简介 CentOS,是基于 Red Hat Linux 提供的可自由使用源代码的企业级 Linux 发行版本;是一个稳定,可预测,可管理和可复制的免费企业级计算平台。 配置方法 1. 备份
|
1 |
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup |
2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/ CentOS 6
|
1 |
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo |
或者
|
1 |
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo |
CentOS 7
|
1 |
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo |
或者
|
1 |
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo |
CentOS 8
|
1 |
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo |
或者
|
1 |
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo |
3. 运行 yum makecache 生成缓存 4. 其他 非阿里云ECS用户会出现 Couldn’t resolve host 'mirrors.cloud.aliyuncs.com' 信息,不影响使用。用户也可自行修改相关配置: eg:
|
1 |
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo |
相关链接 下载地址: https://mirrors.aliyun.com/centos/ https://mirrors.aliyun.com/centos-vault/ 官方主页: http://www.centos.org/ 邮件列表: http://www.centos.org/modules/tinycontent/index.php?id=16 论坛: http://www.centos.org/modules/newbb/ 文档: http://www.centos.org/docs/ Wiki: http://wiki.centos.org/ from:https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11VQZfmr
View Details网上常见方法 网上太多文章通过修改Program文件方法进行修改。例如这样 修改配置文件的方法 将配置文件按照这样修改就行了
|
1 2 3 4 5 6 7 |
"Kestrel": { "EndPoints": { "Http": { "Url": "http://0.0.0.0:5003" // 端口自己改吧 } } } |
写在后面 更多配置参考 https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1 也有有些人搞不懂,为什么要这样写呢,无论是iis,nginx,tomcat 等等这些web服务程序都有自己的配置规则。那是没问题的。但是如果你想要直接用Kestrel呢,这样做绝对是非常棒的,而且可以放到树莓派等小型机器中直接作为服务使用。非常棒。 还有一种就是在本地开发的debug时候,这样可以防止端口冲突,如果是debug,还可以修改launchSettings.json文件进行修改端口。这个文件的修改方式我就不多说了,自己看看里面的配置应该也会很清楚了(这个文件简单修改还可以,自己写一些复杂的系统变量就搞不懂了) 引用 https://www.cnblogs.com/goldenbiu/articles/10755213.html https://www.cnblogs.com/Allen0910/p/8550873.html from:https://blog.csdn.net/iml6yu/article/details/100692488
View Details今天负责部署一个小项目,眼看到最后一步跑服务的时候报错了: Process: 2451 ExecStart=/home/.virtualenvs/bin/python /home/xxx.py (code=exited, status=217/USER) 仔细一看原来原来service文件的用户名没改,难怪提示217/USER错误呢,把用户名改对就好了,服务顺利跑起来了 [Unit] Description=xxx After=network.target [Service] WorkingDirectory=/home/deploy/server User=xxx ExecStart=/home/.virtualenvs/bin/python /home/deploy/server/xxx.py Restart=on-failure [Install] WantedBy=multi-user.target ———————————————— 版权声明:本文为CSDN博主「wangjinyu124419」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/u011519550/java/article/details/83588218
View Details