json-server详解

零、文章目录

json-server详解

1、简介

  • Json-server 是一个零代码快速搭建本地 RESTful API 的工具。它使用 JSON 文件作为数据源,并提供了一组简单的路由和端点,可以模拟后端服务器的行为。
  • github地址:https://github.com/typicode/json-server
  • npm地址:https://www.npmjs.com/package/json-server

2、安装

  • json-server是基于npm安装的,安装了node就自动安装了npm,所以安装json-server需要先安装node,node相关知识请参考node入门,npm相关知识请参考npm入门。
  • 安装json-server:使用npm或yarn全局安装json-server。
npm install -g json-server
  • 验证安装是否成功:显示版本号就是安装成功了
json-server -v

3、快速使用

  1. 创建JSON文件:创建一个JSON文件作为数据源,例如 db.json,并在其中定义你想要模拟的数据,例如:
{"users": [{ "id": 1, "name": "John" },{ "id": 2, "name": "Jane" }]
}
  1. 启动json-server:使用以下命令启动json-server,并将JSON文件作为参数传递给服务器。这将在本地计算机的3000端口上启动服务器,并将db.json文件中的数据暴露为RESTful API。
json-server --watch db.json
  1. 使用API:可以使用Web浏览器或任何HTTP客户端程序(如Postman)来访问json-server提供的的数据。例如,以下URL将检索JSON文件中的所有用户:
http://localhost:3000/users

4、参数说明

  • 语法:json-server [options] <source>
参数简写说明默认值
–config-c指定配置文件路径json-server.json
–port-p指定端口3000
–host-H指定主机名localhost
–watch-w监控文件变化
–routes-r指定路由文件路径
–middlewares-m指定中间件文件路径
–static-s指定静态文件文件夹路径
–read-only–ro指定只允许get请求
–no-cors–nc禁止跨域共享
–no-gzip–ng禁止gzip压缩
–snapshots-S指定快照目录.
–delay-d指定延迟返回时长(ms)
–id-i指定数据库的ID属性id
–foreignKeySuffix–fks指定外键前缀Id
–quiet-q抑制来自输出的日志消息
–help-h显示帮助
–version-v显示版本号

(1)创建json数据

  • 在空文件夹test下,执行命令
json-server --watch db.json

image-20230728154308519

  • 文件夹下就会生成一个默认内容的db.json文件
{"posts": [{"id": 1,"title": "json-server","author": "typicode"}],"comments": [{"id": 1,"body": "some comment","postId": 1}],"profile": {"name": "typicode"}
}
  • 访问地址http://localhost:3000/会展示如下页面,可以分别点击/posts /comment /profile 链接,能看到各自的json数据。http://localhost:3000/db链接能访问到完整的数据。

image-20230728154558123

(2)修改端口

  • json-server 默认是 3000 端口,我们也可以自己指定端口,指令如下:
json-server --watch db.json --port 8887

(3)使用配置文件

  • 通过命令行配置会让命令变的很长,而且容易敲错;
  • json-server允许我们把所有的配置放到一个配置文件中,这个配置文件一般命名为json_sever_config.json
{"port": 8887,            "watch": true,"read-only": false, "no-cors": false, "no-gzip": false
}
  • 然后启动服务命令如下
json-server -c json_sever_config.json db.json

(4)静态服务器

  • 可以配置静态服务器,./static是静态文件路径,里面放一张图片test.jpg
  • 服务启动后,直接在浏览器输入http://localhost:3000/test.jpg就能访问到这张图片
json-server -s ./static db.json

5、增删改查

(1)准备数据

  • 我们准本一个测试数据db.json,这是15篇文章内容数据,注意数据格式要符合JSON格式,如果数据格式有误,命令窗口会报错,可以根据错误提示进行修整。
  • 启动服务:json-server --watch db.json
{"articles": [{"userId": 1,"id": 1,"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit","body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"},{"userId": 1,"id": 2,"title": "qui est esse","body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"},{"userId": 1,"id": 3,"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut","body": "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut"},{"userId": 2,"id": 11,"title": "et ea vero quia laudantium autem","body": "delectus reiciendis molestiae occaecati non minima eveniet qui voluptatibus\naccusamus in eum beatae sit\nvel qui neque voluptates ut commodi qui incidunt\nut animi commodi"},{"userId": 2,"id": 12,"title": "in quibusdam tempore odit est dolorem","body": "itaque id aut magnam\npraesentium quia et ea odit et ea voluptas et\nsapiente quia nihil amet occaecati quia id voluptatem\nincidunt ea est distinctio odio"},{"userId": 2,"id": 13,"title": "dolorum ut in voluptas mollitia et saepe quo animi","body": "aut dicta possimus sint mollitia voluptas commodi quo doloremque\niste corrupti reiciendis voluptatem eius rerum\nsit cumque quod eligendi laborum minima\nperferendis recusandae assumenda consectetur porro architecto ipsum ipsam"},{"userId": 3,"id": 21,"title": "asperiores ea ipsam voluptatibus modi minima quia sint","body": "repellat aliquid praesentium dolorem quo\nsed totam minus non itaque\nnihil labore molestiae sunt dolor eveniet hic recusandae veniam\ntempora et tenetur expedita sunt"},{"userId": 3,"id": 22,"title": "dolor sint quo a velit explicabo quia nam","body": "eos qui et ipsum ipsam suscipit aut\nsed omnis non odio\nexpedita earum mollitia molestiae aut atque rem suscipit\nnam impedit esse"},{"userId": 3,"id": 23,"title": "maxime id vitae nihil numquam","body": "veritatis unde neque eligendi\nquae quod architecto quo neque vitae\nest illo sit tempora doloremque fugit quod\net et vel beatae sequi ullam sed tenetur perspiciatis"},{"userId": 4,"id": 31,"title": "ullam ut quidem id aut vel consequuntur","body": "debitis eius sed quibusdam non quis consectetur vitae\nimpedit ut qui consequatur sed aut in\nquidem sit nostrum et maiores adipisci atque\nquaerat voluptatem adipisci repudiandae"},{"userId": 4,"id": 32,"title": "doloremque illum aliquid sunt","body": "deserunt eos nobis asperiores et hic\nest debitis repellat molestiae optio\nnihil ratione ut eos beatae quibusdam distinctio maiores\nearum voluptates et aut adipisci ea maiores voluptas maxime"},{"userId": 4,"id": 33,"title": "qui explicabo molestiae dolorem","body": "rerum ut et numquam laborum odit est sit\nid qui sint in\nquasi tenetur tempore aperiam et quaerat qui in\nrerum officiis sequi cumque quod"},{"userId": 5,"id": 41,"title": "non est facere","body": "molestias id nostrum\nexcepturi molestiae dolore omnis repellendus quaerat saepe\nconsectetur iste quaerat tenetur asperiores accusamus ex ut\nnam quidem est ducimus sunt debitis saepe"},{"userId": 5,"id": 42,"title": "commodi ullam sint et excepturi error explicabo praesentium voluptas","body": "odio fugit voluptatum ducimus earum autem est incidunt voluptatem\nodit reiciendis aliquam sunt sequi nulla dolorem\nnon facere repellendus voluptates quia\nratione harum vitae ut"},{"userId": 5,"id": 43,"title": "eligendi iste nostrum consequuntur adipisci praesentium sit beatae perferendis","body": "similique fugit est\nillum et dolorum harum et voluptate eaque quidem\nexercitationem quos nam commodi possimus cum odio nihil nulla\ndolorum exercitationem magnam ex et a et distinctio debitis"}]
}

(2)获取全部数据

  • 获取所有文章内容,返回对象数组
http://localhost:3000/articles

(3)过滤条件

  • 根据id获取数据,返回单个对象
http://localhost:3000/articles/1
{"userId": 1,"id": 1,"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit","body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
  • 还可以用url参数写法,返回对象数组
http://localhost:3000/articles?id=1
[{"userId": 1,"id": 1,"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit","body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"}
]
  • 也可以指定多个条件,用&符号连接,返回对象数组
http://localhost:3000/articles?userId=1&id=1
[{"userId": 1,"id": 1,"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit","body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"}
]
  • _gte_lte 来设置一个字段的取值范围。包含开头和结尾。
http://localhost:3000/articles?id_gte=1&id_lte=12
[{"userId": 1,"id": 1,"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit","body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"},{"userId": 1,"id": 2,"title": "qui est esse","body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"},{"userId": 1,"id": 3,"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut","body": "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut"},{"userId": 2,"id": 11,"title": "et ea vero quia laudantium autem","body": "delectus reiciendis molestiae occaecati non minima eveniet qui voluptatibus\naccusamus in eum beatae sit\nvel qui neque voluptates ut commodi qui incidunt\nut animi commodi"},{"userId": 2,"id": 12,"title": "in quibusdam tempore odit est dolorem","body": "itaque id aut magnam\npraesentium quia et ea odit et ea voluptas et\nsapiente quia nihil amet occaecati quia id voluptatem\nincidunt ea est distinctio odio"}
]
  • _ne来设置不包含某个值。
http://localhost:3000/articles?id_ne=1&id_ne=2
[{"userId": 1,"id": 3,"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut","body": "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut"},{"userId": 2,"id": 11,"title": "et ea vero quia laudantium autem","body": "delectus reiciendis molestiae occaecati non minima eveniet qui voluptatibus\naccusamus in eum beatae sit\nvel qui neque voluptates ut commodi qui incidunt\nut animi commodi"},{"userId": 2,"id": 12,"title": "in quibusdam tempore odit est dolorem","body": "itaque id aut magnam\npraesentium quia et ea odit et ea voluptas et\nsapiente quia nihil amet occaecati quia id voluptatem\nincidunt ea est distinctio odio"}......
]
  • _start 来指定开始位置, _end 来指定结束位置,或者是用_limit来指定从开始位置起往后取几个数据。不包含_start,包含_end
http://localhost:3000/articles?_start=2&_end=5
[{"userId": 1,"id": 3,"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut","body": "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut"},{"userId": 2,"id": 11,"title": "et ea vero quia laudantium autem","body": "delectus reiciendis molestiae occaecati non minima eveniet qui voluptatibus\naccusamus in eum beatae sit\nvel qui neque voluptates ut commodi qui incidunt\nut animi commodi"},{"userId": 2,"id": 12,"title": "in quibusdam tempore odit est dolorem","body": "itaque id aut magnam\npraesentium quia et ea odit et ea voluptas et\nsapiente quia nihil amet occaecati quia id voluptatem\nincidunt ea est distinctio odio"}
]
  • _like来设置模糊匹配某个字段
http://localhost:3000/articles?id_like=3
[{"userId": 1,"id": 3,"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut","body": "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut"},{"userId": 2,"id": 13,"title": "dolorum ut in voluptas mollitia et saepe quo animi","body": "aut dicta possimus sint mollitia voluptas commodi quo doloremque\niste corrupti reiciendis voluptatem eius rerum\nsit cumque quod eligendi laborum minima\nperferendis recusandae assumenda consectetur porro architecto ipsum ipsam"},{"userId": 3,"id": 23,"title": "maxime id vitae nihil numquam","body": "veritatis unde neque eligendi\nquae quod architecto quo neque vitae\nest illo sit tempora doloremque fugit quod\net et vel beatae sequi ullam sed tenetur perspiciatis"},{"userId": 4,"id": 31,"title": "ullam ut quidem id aut vel consequuntur","body": "debitis eius sed quibusdam non quis consectetur vitae\nimpedit ut qui consequatur sed aut in\nquidem sit nostrum et maiores adipisci atque\nquaerat voluptatem adipisci repudiandae"},{"userId": 4,"id": 32,"title": "doloremque illum aliquid sunt","body": "deserunt eos nobis asperiores et hic\nest debitis repellat molestiae optio\nnihil ratione ut eos beatae quibusdam distinctio maiores\nearum voluptates et aut adipisci ea maiores voluptas maxime"},{"userId": 4,"id": 33,"title": "qui explicabo molestiae dolorem","body": "rerum ut et numquam laborum odit est sit\nid qui sint in\nquasi tenetur tempore aperiam et quaerat qui in\nrerum officiis sequi cumque quod"},{"userId": 5,"id": 43,"title": "eligendi iste nostrum consequuntur adipisci praesentium sit beatae perferendis","body": "similique fugit est\nillum et dolorum harum et voluptate eaque quidem\nexercitationem quos nam commodi possimus cum odio nihil nulla\ndolorum exercitationem magnam ex et a et distinctio debitis"}
]
  • q 来设置全文搜索
http://localhost:3000/articles?q=maxime
[{"userId": 3,"id": 23,"title": "maxime id vitae nihil numquam","body": "veritatis unde neque eligendi\nquae quod architecto quo neque vitae\nest illo sit tempora doloremque fugit quod\net et vel beatae sequi ullam sed tenetur perspiciatis"},{"userId": 4,"id": 32,"title": "doloremque illum aliquid sunt","body": "deserunt eos nobis asperiores et hic\nest debitis repellat molestiae optio\nnihil ratione ut eos beatae quibusdam distinctio maiores\nearum voluptates et aut adipisci ea maiores voluptas maxime"}
]

(4)数据分页

  • 分页采用 _page 来设置页码, _limit 来控制每页显示条数。如果没有指定 _limit ,默认每页10条。
http://localhost:3000/articles?_page=2&_limit=3
[{"userId": 2,"id": 11,"title": "et ea vero quia laudantium autem","body": "delectus reiciendis molestiae occaecati non minima eveniet qui voluptatibus\naccusamus in eum beatae sit\nvel qui neque voluptates ut commodi qui incidunt\nut animi commodi"},{"userId": 2,"id": 12,"title": "in quibusdam tempore odit est dolorem","body": "itaque id aut magnam\npraesentium quia et ea odit et ea voluptas et\nsapiente quia nihil amet occaecati quia id voluptatem\nincidunt ea est distinctio odio"},{"userId": 2,"id": 13,"title": "dolorum ut in voluptas mollitia et saepe quo animi","body": "aut dicta possimus sint mollitia voluptas commodi quo doloremque\niste corrupti reiciendis voluptatem eius rerum\nsit cumque quod eligendi laborum minima\nperferendis recusandae assumenda consectetur porro architecto ipsum ipsam"}
]

(5)截取数据

  • (6)数据排序

  • _sort 指定要排序的字段, _order 指定正序还是逆序(asc | desc ,默认是asc)

http://localhost:3000/articles?_sort=id&_order=desc
[{"userId": 5,"id": 43,"title": "eligendi iste nostrum consequuntur adipisci praesentium sit beatae perferendis","body": "similique fugit est\nillum et dolorum harum et voluptate eaque quidem\nexercitationem quos nam commodi possimus cum odio nihil nulla\ndolorum exercitationem magnam ex et a et distinctio debitis"},{"userId": 5,"id": 42,"title": "commodi ullam sint et excepturi error explicabo praesentium voluptas","body": "odio fugit voluptatum ducimus earum autem est incidunt voluptatem\nodit reiciendis aliquam sunt sequi nulla dolorem\nnon facere repellendus voluptates quia\nratione harum vitae ut"},{"userId": 5,"id": 41,"title": "non est facere","body": "molestias id nostrum\nexcepturi molestiae dolore omnis repellendus quaerat saepe\nconsectetur iste quaerat tenetur asperiores accusamus ex ut\nnam quidem est ducimus sunt debitis saepe"},......
]
  • 还可以指定多个字段排序,先排前面字段,前面字段相同的再排第二个字段
http://localhost:3000/articles?_sort=userId,id&_order=desc,asc
[{"userId": 5,"id": 41,"title": "non est facere","body": "molestias id nostrum\nexcepturi molestiae dolore omnis repellendus quaerat saepe\nconsectetur iste quaerat tenetur asperiores accusamus ex ut\nnam quidem est ducimus sunt debitis saepe"},{"userId": 5,"id": 42,"title": "commodi ullam sint et excepturi error explicabo praesentium voluptas","body": "odio fugit voluptatum ducimus earum autem est incidunt voluptatem\nodit reiciendis aliquam sunt sequi nulla dolorem\nnon facere repellendus voluptates quia\nratione harum vitae ut"},{"userId": 5,"id": 43,"title": "eligendi iste nostrum consequuntur adipisci praesentium sit beatae perferendis","body": "similique fugit est\nillum et dolorum harum et voluptate eaque quidem\nexercitationem quos nam commodi possimus cum odio nihil nulla\ndolorum exercitationem magnam ex et a et distinctio debitis"},{"userId": 4,"id": 31,"title": "ullam ut quidem id aut vel consequuntur","body": "debitis eius sed quibusdam non quis consectetur vitae\nimpedit ut qui consequatur sed aut in\nquidem sit nostrum et maiores adipisci atque\nquaerat voluptatem adipisci repudiandae"},{"userId": 4,"id": 32,"title": "doloremque illum aliquid sunt","body": "deserunt eos nobis asperiores et hic\nest debitis repellat molestiae optio\nnihil ratione ut eos beatae quibusdam distinctio maiores\nearum voluptates et aut adipisci ea maiores voluptas maxime"},{"userId": 4,"id": 33,"title": "qui explicabo molestiae dolorem","body": "rerum ut et numquam laborum odit est sit\nid qui sint in\nquasi tenetur tempore aperiam et quaerat qui in\nrerum officiis sequi cumque quod"}......
]

(6)添加数据

  • 可以使用api调用工具apifox直接调用,返回值是完整的数据对象

image-20230729233100589

  • 也可以使用ajax发起请求
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>添加数据</title><script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
</head><body><button id="add">添加数据</button><script>//添加数据$("#add").click(function() {$.ajax({type: 'post',url: 'http://localhost:3000/articles',data: {userId: 6,id: 51,title: '添加数据',body: '添加数据'},success: function(data) {console.log("post success")},error: function() {alert("post error")}})})</script>
</body></html>

(7)更新数据

  • 接口调试工具

image-20230730215748369

  • ajax请求
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>更新数据</title><script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
</head><body><button id="update">更新数据</button><script>//更新数据$("#update").click(function() {$.ajax({type: 'put',url: 'http://localhost:3000/articles/51',data: {userId: 7,title: '更新数据',body: '更新数据'},success: function(data) {console.log("put success")},error: function() {alert("put error")}})})</script>
</body></html>

(8)删除数据

  • 接口调试工具

image-20230730220035037

  • ajax请求
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>删除数据</title><script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
</head><body><button id="delete">删除数据</button><script>//删除数据$("#delete").click(function() {$.ajax({type: 'delete',url: 'http://localhost:3000/articles/51',dataType: "json",success: function(data) {console.log("delete success")},error: function() {alert("delete error")}})})</script>
</body></html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/15606.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

芯片制造详解.刻蚀原理.学习笔记(五)

本篇笔记是看完原视频后的整理和补充&#xff0c;建议各位观看原视频&#xff0c;这里附上地址。 如何雕刻芯片&#xff1a;刻蚀原理&#xff5c;芯片制造详解05 芯片制造详解.刻蚀原理.学习笔记 五 一、刻蚀技术的分类二、刻蚀中三个关键指标2.1 刻蚀速率2.2 选择比2.3 方向性…

pytorch学习——线性神经网络——1线性回归

概要&#xff1a;线性神经网络是一种最简单的神经网络模型&#xff0c;它由若干个线性变换和非线性变换组成。线性变换通常表示为矩阵乘法&#xff0c;非线性变换通常是一个逐元素的非线性函数。线性神经网络通常用于解决回归和分类问题。 一.线性回归 线性回归是一种常见的机…

RISC-V公测平台发布 · 如何在SG2042上玩转k3s

前言 Kubernetes是一个开源的容器管理平台&#xff0c;通过Kubernetes的跨集群管理功能&#xff0c;用户可以方便地进行应用程序的复制、迁移和跨云平台的部署。 而k3s作为Kubernetes的轻量级发行版&#xff0c;相比传统的Kubernetes具有更小的二进制文件大小和更低的资源消耗…

#typescript 使用file-saver模块#

场景&#xff1a;前端使用file-saver模块做导出文档的时候&#xff0c;出现两个错误 1&#xff1a;npm run build 提示找不到模块&#xff0c;如图 解决方法&#xff1a; 先卸载&#xff0c;不管是否安装都先要卸载 ,然后安装&#xff1a; npm uninstall file-saver npm…

流星特效案例代码

实际效果&#xff0c;代码下载即可使用 流星图片 <!-- 描述: 流星特效 作者: Jack GUO 日期: 20230727 --> <template> <div class"wrap-container sn-container"> <div class"pd-main-left"> <div class"yun-container&…

Flutter环境搭建踩坑集锦

Flutter 背景准备工作先检查一下自己的电脑&#xff0c;看一下是不是满足配置要求下载安装配置环境下载安装JDK下载安装Android studio下载Flutterflutter doctor故障Android license status unknownNetwork resources 故障 后记 背景 发现一个不错的框架Flutter&#xff0c;听…

线程同步问题——锁

文章目录 线程同步互斥锁&#xff08;互斥量&#xff09;相关操作函数应用 死锁读写锁相关操作函数 线程同步 临界区——代码 临界数据——共享数据 原子操作&#xff1a;不可以被其他操作打断 必须的&#xff0c;用以保证数据的安全性 实现线程同步的方式&#xff1a; 互斥量…

什么是 DNS ANAME 解析?

本人使用谷歌搜索了简中互联网&#xff0c;完全没有找到任何有关 ANAME 的文章……本文该不会是头一份吧 相信大家对于 DNS 的解析方式都不陌生&#xff0c;常见的有 A、CNAME、MX、TXT 记录等等。其中&#xff0c;网站常用的是 A 记录和 CNAME 记录&#xff1a;A 记录用于将域…

【Django学习】(十六)session_token认证过程与区别_响应定制

一、认识session与token 这里就直接引用别人的文章&#xff0c;不做过多说明 网络应用中session和token本质是一样的吗&#xff0c;有什么区别&#xff1f; - 知乎 二、token响应定制 在全局配置表中配置 DEFAULT_AUTHENTICATION_CLASSES: [# 指定jwt Token认证rest_framew…

记一次安装nvm切换node.js版本实例详解

最后效果如下&#xff1a; 背景&#xff1a;由于我以前安装过node.js&#xff0c;后续想安装nvm将node.js管理起来。 问题&#xff1a;nvm-use命令行运行成功&#xff0c;但是nvm-list显示并没有成功。 原因&#xff1a;因为安装过node.js&#xff0c;所以原先的node.js不收n…

Android复习(Android基础-四大组件)—— Activity

Activity作为四大组件之首&#xff0c;是使用最为频繁的一种组件&#xff0c;中文直接翻译为"活动"&#xff0c;不过如果被翻译为"界面"会更好理解。正常情况&#xff0c;除了Window&#xff0c;Dialog和Toast &#xff0c; 我们能见到的界面只有Activity。…

RT1052 的四定时器

文章目录 1 Quad Timer&#xff0c;简称&#xff1a;QTMR2 单个通道的框图3 QTMR配置3.1 QTMR1 时钟使能。3.2 初始化 QTMR1。3.2.1 QTMR_Init 3.3 设置 QTMR1 通道 0 的定时周期。3.3.1QTMR_SetTimerPeriod 3.4 使能 QTMR1 通道 0 的比较中断。3.4.1 QTMR_EnableInterrupts 3.…

Docker安装 Mysql 8.x 版本

文章目录 Docker安装 Mysql 8.0.22Mysql 创建账号并授权Mysql 数据迁移同版本数据迁移跨版本数据迁移 Mysql 5.x 版本与 Mysql 8.x版本是两个大版本&#xff0c;这里演示安装Mysql 8.x版本 Docker安装 Mysql 8.0.22 # 下载mysql $ docker pull mysql 默认安装最新…

web学习

TCP/IP体系结构&#xff08;IP和端口&#xff09;&#xff1a; IP是什么&#xff1a;是计算机在互联网上的唯一标识&#xff08;坐标&#xff0c;代号&#xff09;&#xff0c;用于在互联网中寻找计算机。 访问网站时&#xff1a;域名会通过DNS&#xff08;解析服务&#xff…

Vue通过指令 命令将打包好的dist静态文件上传到腾讯云存储桶 (保存原有存储目录结构)

1、在项目根目录创建uploadToCOS.js文件 &#xff08;建议起简单的名字 方便以后上传输入命令方便&#xff09; 2、uploadToCOS.js文件代码编写 const path require(path); const fs require(fs); const COS require(cos-nodejs-sdk-v5);// 配置腾讯云COS参数 const cos n…

工程师是怎样对待开源

工程师如何对待开源 本文是笔者作为一个在知名科技企业内从事开源相关工作超过 20 年的工程师&#xff0c;亲身经历或者亲眼目睹很多工程师对待开源软件的优秀实践&#xff0c;也看到了很多 Bad Cases&#xff0c;所以想把自己的一些心得体会写在这里&#xff0c;供工程师进行…

跨域冲突问题解决

1、问题分析 服务端和nginx代理 都做了跨域配置&#xff0c;导致请求头重复 headers 里面有两个重复的 Access-Control-Allow-Origin Access-Control-Allow-Methods Access-Control-Allow-Credentials 2、解决方法 在nginx去除服务端的跨域配置 proxy_hide_header Access-…

铁路关基保护新规:优先采购安全可信的网络产品和服务!

《征求意见稿》第十四条提到&#xff1a;运营者应当加强供应链安全保护&#xff0c;优先采购安全可信的网络产品和服务&#xff1b;采购网络产品和服务影响或者可能影响国家安全的&#xff0c;运营者应当预判网络产品和服务投入使用后可能带来的国家安全风险&#xff0c;按照国…

quarkus核心编程笔记

此篇只做总结&#xff0c;有大佬做的更详细 大佬quarkus笔记 依赖注入 在应用中&#xff0c;一个接口有多个实现是很常见的&#xff0c;那么依赖注入时&#xff0c;如果类型是接口&#xff0c;如何准确选择实现呢&#xff1f; 修饰符匹配Named注解属性匹配根据优先级选择写…