初始化知识库
This commit is contained in:
64
repos/.vitepress/config.js
Normal file
64
repos/.vitepress/config.js
Normal file
@@ -0,0 +1,64 @@
|
||||
export default ({
|
||||
lang: 'zh-CN',
|
||||
title: '查尔斯的知识库',
|
||||
description: '个人知识库,记录 & 分享个人碎片化、结构化、体系化的知识内容。',
|
||||
|
||||
lastUpdated: true, // 启用最后更新时间
|
||||
|
||||
// <head>设置
|
||||
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 类型数据问题' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
31
repos/index.md
Normal file
31
repos/index.md
Normal file
@@ -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: 关于分享,有形的东西越分越少,无形的东西越分越多。在记录与分享的过程中, 梳理所学, 交流所得, 必有所获。
|
||||
---
|
||||
|
139
repos/issues/2022/01/JavaScript 无法存储 Java Long 类型数据问题.md
Normal file
139
repos/issues/2022/01/JavaScript 无法存储 Java Long 类型数据问题.md
Normal file
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
在前端表单中的展示效果大概如下:
|
||||
|
||||

|
||||
|
||||
## 原因分析
|
||||
|
||||
笔者相信各位同学都应该猜得到,当提交表单的时候,前端肯定会把选中的镜像的 val 值传递给后端,然后由后端继续进行处理。
|
||||
|
||||
但是就在这个环节,由前端传给后端的 val 值竟然错了,例如:当选中了 CentOS 8.1 64 位这个镜像时,本该传递的 val 值为 8014753905961037835,实际传递的却是: 8014753905961038000。
|
||||
|
||||
后端接口测试的响应数据没问题,那问题显然就是出在前端了。
|
||||
|
||||
最终,配合前端开发定位这个问题的原因是因为: JavaScript 中无法存储 Java 中的 Long 类型数据,当位数超过 JavaScript 整数存储的范围,就会以0来代替了。
|
||||
|
||||

|
||||
|
||||
## 解决方案
|
||||
|
||||
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
|
||||
}
|
||||
```
|
5
repos/issues/index.md
Normal file
5
repos/issues/index.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Bug万象集
|
||||
|
||||
::: warning
|
||||
你读过的书,遇过的人,扛过的事,写过的 Bug,构成了你开发者人生的格局。:smile:
|
||||
:::
|
1
repos/public/CNAME
Normal file
1
repos/public/CNAME
Normal file
@@ -0,0 +1 @@
|
||||
blog.charles7c.top
|
BIN
repos/public/favicon.ico
Normal file
BIN
repos/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
BIN
repos/public/img/2022/01/202201260941889.png
Normal file
BIN
repos/public/img/2022/01/202201260941889.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
BIN
repos/public/img/2022/01/202201260942561.png
Normal file
BIN
repos/public/img/2022/01/202201260942561.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
repos/public/logo.jpg
Normal file
BIN
repos/public/logo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
Reference in New Issue
Block a user