commit 54a5479720a62573a5f6d1a7f2605a608a620afe Author: Charles7c Date: Wed Jul 6 19:57:16 2022 +0800 初始化知识库 diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml new file mode 100644 index 000000000..4524c0326 --- /dev/null +++ b/.github/workflows/deploy-pages.yml @@ -0,0 +1,60 @@ +name: Deploy Pages + +on: + # 推送时执行 + push: + branches: [main, master] + # pr时执行 + pull_request: + branches: [main, master] + # 定时执行 00:01 + schedule: + - cron: 1 0 * * * + # 可手动执行 + workflow_dispatch: + +jobs: + # 任务1: 部署 GitHub Pages + deploy-github-pages: + runs-on: ubuntu-latest + + steps: + # 1、检出源码 + - name: Checkout + uses: actions/checkout@v3 + + # 2、安装模块并打包 + - name: Install and Build + run: | + yarn install + yarn build + + # 3、部署 GitHub Pages + - name: Deploy GitHub Pages + uses: JamesIves/github-pages-deploy-action@v4 + with: + BRANCH: pages + FOLDER: repos/.vitepress/dist + + # 任务2: 部署 Gitee Pages + deploy-gitee-pages: + runs-on: ubuntu-latest + steps: + # 1、同步内容到 Gitee + - name: Sync to Gitee + uses: wearerequired/git-mirror-action@master #使用action库 + env: + SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }} #Gitee私钥 + with: + source-repo: git@github.com:Charles7c/charles7c.github.io.git #GitHub 源仓库地址 + destination-repo: git@gitee.com:Charles7c/charles7c.git #Gitee 目标仓库地址 + # 2、部署 Gitee Pages + - name: Deploy Gitee Pages + # 手动执行时只同步内容, 不进行部署 + if: github.event_name != 'workflow_dispatch' + uses: yanglbme/gitee-pages-action@main + with: + gitee-username: ${{ secrets.GITEE_USERNAME }} #Gitee 用户名 + gitee-password: ${{ secrets.GITEE_PASSWORD }} #Gitee 密码 + gitee-repo: Charles7c/charles7c #Gitee 仓库 + branch: pages #要部署的分支,默认是 master,若是其他分支,则需要指定(指定的分支必须存在) \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1d60a35bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Node modules +node_modules/ + +# Dist files +dist/ +lib/ + +# Test coverage files +coverage/ + +# MacOS Desktop Services Store +.DS_Store + +# Log files +*.log + +# IDE setting files +.idea +.vscode + +# Temp files +yarn.lock +package-lock.json +.vite_opt_cache + +# Other files +/src/client/shared.ts +/src/node/shared.ts +pnpm-global +TODOs.md \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..bd0b8f9aa --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright © 2019-present Charles7c + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.en.md b/README.en.md new file mode 100644 index 000000000..12c1b5a74 --- /dev/null +++ b/README.en.md @@ -0,0 +1,22 @@ +English | [中文](./README.md) + +

Charles's Repositories

+

+ + + + + + + + + +

+

+ 📝 This is the charles's personal knowledge repositories website. +

+

+ 🐢 GitHub Pages:https://blog.charles7c.top
+ 🐇 Gitee Pages:https://charles7c.gitee.io +

+ diff --git a/README.md b/README.md new file mode 100644 index 000000000..41e8c4437 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +[English](./README.en.md) | 中文 + +

查尔斯的知识库

+

+ + + + + + + + + +

+

+ 📝 查尔斯的个人知识库,记录 & 分享个人碎片化、结构化、体系化的知识内容。 +

+

+ 🐢 GitHub Pages:https://blog.charles7c.top
+ 🐇 Gitee Pages:https://charles7c.gitee.io +

+ diff --git a/package.json b/package.json new file mode 100644 index 000000000..76241ed51 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "MyRepos", + "version": "1.0.0", + "description": "Charles's personal knowledge repositories.", + "main": "index.js", + "author": "Charles7c", + "license": "MIT", + "scripts": { + "dev": "vitepress dev repos", + "build": "vitepress build repos", + "serve": "vitepress serve repos" + }, + "devDependencies": { + "vitepress": "^1.0.0-alpha.4", + "vue": "^3.2.37" + } +} diff --git a/repos/.vitepress/config.js b/repos/.vitepress/config.js new file mode 100644 index 000000000..174c98215 --- /dev/null +++ b/repos/.vitepress/config.js @@ -0,0 +1,64 @@ +export default ({ + lang: 'zh-CN', + title: '查尔斯的知识库', + description: '个人知识库,记录 & 分享个人碎片化、结构化、体系化的知识内容。', + + lastUpdated: true, // 启用最后更新时间 + + // 设置 + head: [ + ['link', { rel: 'icon', href: '/favicon.ico' }] + ], + + themeConfig: { + logo: '/logo.jpg', + lastUpdatedText: '最后更新时间', // 最后更新时间文本 + docFooter: { + prev: '上一页', + next: '下一页' + }, + // 编辑链接 + editLink: { + pattern: 'https://github.com/Charles7c/charles7c.github.io/edit/main/repos/:path', + text: '在 GitHub 上编辑此页面' + }, + + // 社交链接 + socialLinks: [ + { icon: 'github', link: 'https://github.com/Charles7c/charles7c.github.io' } + ], + + // 版权标识 + footer: { + message: 'Released under the MIT License.', + copyright: 'Copyright © 2019-present Charles7c' + }, + + // 导航栏 + nav: nav(), + + // 侧边栏 + sidebar: { + '/issues/': sidebarIssues() + } + } +}) + +function nav() { + return [ + { + text: 'Bug万象集', + link: '/issues/index' + } + ] +} + +function sidebarIssues() { + return [ + { + items: [ + { text: 'JavaScript 无法存储 Java Long 类型数据问题', link: '/issues/2022/01/JavaScript 无法存储 Java Long 类型数据问题' } + ] + } + ] +} diff --git a/repos/index.md b/repos/index.md new file mode 100644 index 000000000..4b96232cc --- /dev/null +++ b/repos/index.md @@ -0,0 +1,31 @@ +--- +layout: home + +title: 查尔斯的知识库 +titleTemplate: 个人知识库 + +hero: + name: 查尔斯的知识库 + text: 专注 & 洞察 & 分享 + tagline: 个人知识库,记录 & 分享个人碎片化、结构化、体系化的知识内容。 + #image: /logo.png + actions: + - theme: brand + text: Get Started + link: /issues/ + - theme: alt + text: View on GitHub + link: https://github.com/Charles7c/charles7c.github.io + +features: + - icon: ⚡️ + title: 保持专注 + details: “简单比复杂更难,你必须努力让你的想法变得清晰明了,让它变得简单。一旦你做到了简单,你就能搬动大山。” -- 乔布斯 + - icon: 🌌 + title: 善于洞察 + details: 我既没有突出的理解力,也没有过人的机智。只在觉察那些稍纵即逝的事物并对其进行精细观察的能力上,我可能在普通人之上。 -- 达尔文 + - icon: 🌟 + title: 乐于分享 + details: 关于分享,有形的东西越分越少,无形的东西越分越多。在记录与分享的过程中, 梳理所学, 交流所得, 必有所获。 +--- + diff --git a/repos/issues/2022/01/JavaScript 无法存储 Java Long 类型数据问题.md b/repos/issues/2022/01/JavaScript 无法存储 Java Long 类型数据问题.md new file mode 100644 index 000000000..270bd5f2b --- /dev/null +++ b/repos/issues/2022/01/JavaScript 无法存储 Java Long 类型数据问题.md @@ -0,0 +1,139 @@ +--- +title: JavaScript 无法存储 Java Long 类型数据问题 +author: Charles7c +date: 2022/01/26 09:07 +categories: + - Bug万象集 +tags: + - JavaScript +--- + +# JavaScript 无法存储 Java Long 类型数据问题 + +## 问题描述 + +今天在解决一个需求问题的时候,遇到了一个难得一见的 JS 问题。这个问题大概是和一些同学在开发环境使用 == 来比较包装类型的整数一样,由于比较的数值在缓存范围内,因缘际会的错过了 bug 的出现。 + +简单说一下问题经过,是这样的,笔者这个需求最终要求接口返回一组自定义结构的 k-v (不是单纯的键值对)数据,用于在前端表单中进行分类展示。 + +后端响应的数据结构类似如下: + +```json +{ + "code": 200, + "errorMsg": "", + "result": [ + { + "extend": null, + "items": [ + { + "extend": null, + "key": "CentOS 8.1 64位", + "val": 8014753905961037835 + }, + { + "extend": null, + "key": "CentOS 8.0 64位", + "val": 8014753905961037838 + }, + ], + "key": "CentOS", + "pubProperty": "", + "val": 14 + }, + { + "extend": null, + "items": [ + { + "extend": null, + "key": "RedHat Enterprise Linux 8.0 64位", + "val": 7979917486755315712 + }, + { + "extend": null, + "key": "RedHat Enterprise Linux 7.7 64位", + "val": 8014753905961037829 + } + ], + "key": "Redhat", + "pubProperty": "", + "val": 5 + } + ], + "success": true +} +``` + +在前端表单中的展示效果大概如下: + +![202201260941889](../../../public/img/2022/01/202201260941889.png) + +## 原因分析 + +笔者相信各位同学都应该猜得到,当提交表单的时候,前端肯定会把选中的镜像的 val 值传递给后端,然后由后端继续进行处理。 + +但是就在这个环节,由前端传给后端的 val 值竟然错了,例如:当选中了 CentOS 8.1 64 位这个镜像时,本该传递的 val 值为 8014753905961037835,实际传递的却是: 8014753905961038000。 + +后端接口测试的响应数据没问题,那问题显然就是出在前端了。 + +最终,配合前端开发定位这个问题的原因是因为: JavaScript 中无法存储 Java 中的 Long 类型数据,当位数超过 JavaScript 整数存储的范围,就会以0来代替了。 + +![202201260942561](../../../public/img/2022/01/202201260942561.png) + +## 解决方案 + +JavaScript 存储不了就存储不了吧,咱们这个需求还得解决啊,最终的解决方法就是将后端响应回来的 Long 类型数据转换为字符串。 + +```java +// 在序列化为 JSON 时将该字段转换为 String 类型 +@JsonFormat(shape = JsonFormat.Shape.STRING) +private Long val; +``` + +后端响应的数据结构类似如下: + +```json +{ + "code": 200, + "errorMsg": "", + "result": [ + { + "extend": null, + "items": [ + { + "extend": null, + "key": "CentOS 8.1 64位", + "val": "8014753905961037835" + }, + { + "extend": null, + "key": "CentOS 8.0 64位", + "val": "8014753905961037838" + }, + ], + "key": "CentOS", + "pubProperty": "", + "val": 14 + }, + { + "extend": null, + "items": [ + { + "extend": null, + "key": "RedHat Enterprise Linux 8.0 64位", + "val": "7979917486755315712" + }, + { + "extend": null, + "key": "RedHat Enterprise Linux 7.7 64位", + "val": "8014753905961037829" + } + ], + "key": "Redhat", + "pubProperty": "", + "val": 5 + } + ], + "success": true +} +``` \ No newline at end of file diff --git a/repos/issues/index.md b/repos/issues/index.md new file mode 100644 index 000000000..fff5220e2 --- /dev/null +++ b/repos/issues/index.md @@ -0,0 +1,5 @@ +# Bug万象集 + +::: warning +你读过的书,遇过的人,扛过的事,写过的 Bug,构成了你开发者人生的格局。:smile: +::: \ No newline at end of file diff --git a/repos/public/CNAME b/repos/public/CNAME new file mode 100644 index 000000000..1643c66ad --- /dev/null +++ b/repos/public/CNAME @@ -0,0 +1 @@ +blog.charles7c.top \ No newline at end of file diff --git a/repos/public/favicon.ico b/repos/public/favicon.ico new file mode 100644 index 000000000..dc99ee01b Binary files /dev/null and b/repos/public/favicon.ico differ diff --git a/repos/public/img/2022/01/202201260941889.png b/repos/public/img/2022/01/202201260941889.png new file mode 100644 index 000000000..2678f2697 Binary files /dev/null and b/repos/public/img/2022/01/202201260941889.png differ diff --git a/repos/public/img/2022/01/202201260942561.png b/repos/public/img/2022/01/202201260942561.png new file mode 100644 index 000000000..260235583 Binary files /dev/null and b/repos/public/img/2022/01/202201260942561.png differ diff --git a/repos/public/logo.jpg b/repos/public/logo.jpg new file mode 100644 index 000000000..d692fc64a Binary files /dev/null and b/repos/public/logo.jpg differ