踩坑——紀實

開發踩坑紀實

  • 1 npm安裝
    • 1.1 查看當前的npm鏡像設置
    • 1.2 清空緩存
    • 1.3 修改鏡像
    • 1.4 查看修改結果
    • 1.5 重新安裝vue
  • 2 VScode——NPM腳本窗口找不到
  • 3 springboot項目中updateById()失效
  • 4 前端跨域
    • 4.1 后端加個配置類
    • 4.2 @CrossOrigin注解
  • 5 路由出口
  • 6 springdoc openapi3 swagger3文件上傳
  • 7 連接mysql時出現[HY000][1130] null, message from server: “Host ‘‘ is not allowed報錯
  • 8 Nacos2.2.3 啟動成功但訪問空白
  • 9 ERROR StatusLogger Log4j2 could not find a logging imple mentation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
  • 10 mapper.xml在pom文件中打包后找不到數據源配置了
  • 11 Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled
  • 12 Nacos Whitelabel Error Page 503
  • 13 Mybatis-Plus代碼生成器
  • 14 @RequestBody

1 npm安裝

npm報錯:request to https://registry.npm.taobao.org failed, reason certificate has expired

其實,早在2021年,淘寶就發文稱,npm淘寶鏡像已經從registry.npm.taobao.org切換到了registry.npmmirror.com。舊域名也將于2022年5月31日停止服務(不過,直到今天HTTPS證書到期才真正不能用了)

解決方案

1.1 查看當前的npm鏡像設置

npm config list

1.2 清空緩存

npm cache clean --force

1.3 修改鏡像

npm config set registry https://registry.npmmirror.com

1.4 查看修改結果

1.5 重新安裝vue

npm install -g @vue/cli   #需要管理權限

vue3官網推薦在項目目錄下執行:

npm create vue@latest

2 VScode——NPM腳本窗口找不到

設置UserExtensionsNpm→勾選Enable Run From Folder

點擊項目右上角的...,勾選NPM Scripts

3 springboot項目中updateById()失效

在這里插入圖片描述

實體類繼承自公共實體類BaseEntity,并將主鍵id放進去了,service方法調用getById正常,但是調用updateById時,傳入一個json實體卻獲取不到id,這時,在id上添加注解:@JsonProperty("id")

@JsonProperty(“id”) //入參轉換,為解決前端傳入的json包無法接收
@JsonFiels(name = “id”) //出參轉換

4 前端跨域

http://127.0.0.1:8001/admin/edu/teacher/list/1/5’ from origin ‘http://localhost:9528’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

在這里插入圖片描述

4.1 后端加個配置類

@Configuration
public class CorsConfig implements WebMvcConfigurer {@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOriginPatterns("*") // 允許跨域的域名,*代表任何域名.allowedMethods("GET", "POST") // 允許的方法.allowedHeaders("*") // 允許任何請求頭.allowCredentials(true) // 允許cookies/*.exposedHeaders(HttpHeaders.of("SET_COOKIE",fie))*/.maxAge(3600L);}
}

4.2 @CrossOrigin注解

也可以在Controller上添加該注解

5 路由出口

如果路由指向的頁面組件是同一個,那么路由出口顯示的頁面組件不會重新渲染

為使重新渲染,需要為路由出口定義一個唯一key值

6 springdoc openapi3 swagger3文件上傳

OpenAPI Specification - Version 3.1.0 | Swagger

#Considerations for File Uploads

In contrast with the 2.0 specification, input/output content in OpenAPI is described with the same semantics as any other schema type.file

In contrast with the 3.0 specification, the keyword has no effect on the content-encoding of the schema. JSON Schema offers a keyword, which may be used to specify the for the schema. The keyword supports all encodings defined in RFC4648, including “base64” and “base64url”, as well as “quoted-printable” from RFC2045. The encoding specified by the keyword is independent of an encoding specified by the header in the request or response or metadata of a multipart body – when both are present, the encoding specified in the is applied first and then the encoding specified in the header.format contentEncoding Content-Encoding contentEncoding contentEncoding Content-Type contentEncoding Content-Type

JSON Schema also offers a keyword. However, when the media type is already specified by the Media Type Object’s key, or by the field of an Encoding Object, the keyword SHALL be ignored if present.contentMediaType contentType contentMediaType

原來的寫法:

public void upload(@RequestParam("file") MultipartFile file){}

3.0版本的寫法:

public void upload(@RequestBody(content = @Content(mediaType = "multipart/form-data",schema = @Schema(type = "object"),schemaProperties = {@SchemaProperty(name = "file",schema = @Schema(type = "string",format = "binary"))})) MultipartFile file){}

7 連接mysql時出現[HY000][1130] null, message from server: “Host ‘‘ is not allowed報錯

出現這個問題先考慮端口3306是否開通,如果開通還出現報錯則開始下一步

解決這個問題有個很簡單的方法就是先進入mysql然后命令

use mysql
update user set host='%' where user='root';

然后通過命令

GRANT ALL ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;

8 Nacos2.2.3 啟動成功但訪問空白

修改conf/application.properties文件

### If turn on auth system:
nacos.core.auth.enabled=true### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
#用戶名
nacos.core.auth.server.identity.key=nacos
#密碼
nacos.core.auth.server.identity.value=nacos### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789

9 ERROR StatusLogger Log4j2 could not find a logging imple mentation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console…

添加依賴

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>2.0.13</version>
</dependency><!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.23.1</version>
</dependency>

問題源自于easyexcel

<dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.3.4</version>
</dependency>

10 mapper.xml在pom文件中打包后找不到數據源配置了

mapper.xml文件在src/main/java/mapper/xml中,
在pom文件中添加了打包

<build><!-- 項目打包時會將java目錄中的*.xml文件也進行打包 --><resources><resource><directory>src/main/java</directory><includes><include>**/*.*</include></includes><filtering>false</filtering></resource></resources>
</build>

但是添加后,application.yml就變紅了,運行報錯

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

嘗試把resoources下的application.yml也打包到maven里,成功了。

<build><!-- 項目打包時會將java目錄中的*.xml文件也進行打包 --><resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.yml</include></includes><filtering>false</filtering></resource></resources>
</build>

看來maven默認是都打包,但是如果我自定義的話就要全都定義了。

11 Refused to execute script from because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled

每次打開前端,控制臺都會報錯,雖然不影響運行……

Refused to execute script from 'http://localhost:8080/something/index_bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

某度某應都試過了,無果。在StackOverflow搜索了下,方案:

Your webpack config is malformed. So your devServer is returning the fallback html file instead of the bundle.

Hence why the script is served with the (‘text/html’) MIME type.

devServer: {historyApiFallback:{index:'/dist/index.html'},}

You probably meant something like this:

devServer: {historyApiFallback: true
}

前端的工程只找到了webpack.dev.conf.js,果然有這一行,修改后,成功解決。

12 Nacos Whitelabel Error Page 503

Whitelabel Error Page

This application has no configured error view, so you are seeing this as a fallback.

Tue May 21 04:01:08 CST 2024

[9b38c884-1] There was an unexpected error (type=Service Unavailable, status=503).

用了負載均衡,控制臺一路綠燈過去的,頁面就是刷不出來,惱火。

查得,Nacos在2021版本起就刪除了Ribbon的包,需要引入springcloud-loadbalancer

所以,依賴應該這么引:

<!-- nacos -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency><!-- loadbalancer -->
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>

13 Mybatis-Plus代碼生成器

Spring Boot (v3.2.5)
mybatis-plus-generator (v3.5.6)

Mybatis-Plus代碼生成器配置

14 @RequestBody

如果是來自springframework的注解,則會根據定義自動封裝為Entity,

但如果是swagger的注解,沒有傳的參數就會自動填充為空。

比如User類的主鍵id設置了自增,前端傳入的json中沒有id值,如果是第一種,會自動封裝;如果是第二種,數據庫語句報錯。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/14525.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/14525.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/14525.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C語言函數遞歸

文章目錄 一、遞歸1.遞歸的概念2.遞歸的思想3.遞歸的限制條件 二、遞歸的一些典型例子1.求一個數的階乘2.順序打印一個整數的每一位3.漢諾塔4.青蛙跳臺階5斐波那契數列遞歸和迭代的對比 一、遞歸 1.遞歸的概念 遞歸是學習C語言函數繞不開的一個話題&#xff0c;那什么是遞歸呢…

【算法刷題day56】 Leetcode:647. 回文子串、516. 最長回文子序列

文章目錄 Leetcode 647. 回文子串解題思路代碼總結 Leetcode 516. 最長回文子序列解題思路代碼總結 草稿圖網站 java的Deque Leetcode 647. 回文子串 題目&#xff1a;647. 回文子串 解析&#xff1a;代碼隨想錄解析 解題思路 斜上三角&#xff0c;從左下往上遍歷&#xff0c…

【代碼隨想錄】動態規劃之完全背包問題與打家劫舍問題

前言 更詳細的在大佬的代碼隨想錄 (programmercarl.com) 本系列僅是簡潔版筆記&#xff0c;為了之后方便觀看 完全背包 for(int i 0; i < weight.size(); i) { // 遍歷物品for(int j weight[i]; j < bagWeight; j) { // 遍歷背包容量dp[j] max(dp[j], dp[j - weigh…

ElementPlus Steps步驟條插槽 v-slot:title

<el-steps finish-status"success"><el-stepv-for"item in uniqueReverseArr":status"item.status 2? success: item.status 3? error: item.status 1? finish: process"click.native"stepClick(item)"><templat…

PyTorch中Tensor簡介

PyTorch中所有的操作都是基于Tensor&#xff08;張量&#xff09;的&#xff0c;因此理解張量的含義并能夠自由創建張量是十分必要的。 張量是PyTorch中最基本的操作對象。我們可以用數學中的概念來輔助理解一下張量&#xff0c;如圖5-1所示。 標量&#xff08;Scalar&#x…

c#數據庫的增刪改查

** 安裝數據庫包 ** 在使用 SQLite 數據庫時&#xff0c;你需要安裝適當的 NuGet 包來提供與 SQLite 的集成。 1.打開 Visual Studio 中的你的項目 2.在頂部菜單欄中選擇 “項目” -> “管理 NuGet 包” 3.在 NuGet 管理器中搜索 “System.Data.SQLite” 4.找到適合你項目…

【openlayers系統學習】1.1渲染GeoJSON,添加link交互

一、渲染GeoJSON 在進入編輯之前&#xff0c;我們將看一下使用矢量源和圖層進行基本要素渲染。Workshop在 data? 目錄中包含一個 countries.json? GeoJSON文件。我們首先加載該數據并將其渲染在地圖上。 首先&#xff0c;編輯 index.html? 以便向地圖添加深色背景&#xf…

Vue 組件的生命周期鉤子有哪些用途是什么

Vue 組件的生命周期鉤子提供了在不同階段執行特定邏輯的機會&#xff0c;這些鉤子在組件的創建、掛載、更新、銷毀等過程中被調用。以下是每個生命周期鉤子的常見用途&#xff1a; beforeCreate 用途&#xff1a;由于在這個階段&#xff0c;組件的 data、computed、methods 和…

使用llama.cpp實現LLM大模型的格式轉換、量化、推理、部署

使用llama.cpp實現LLM大模型的量化、推理、部署 大模型的格式轉換、量化、推理、部署概述克隆和編譯環境準備模型格式轉換GGUF格式bin格式 模型量化模型加載與推理模型API服務模型API服務(第三方)GPU推理 大模型的格式轉換、量化、推理、部署 概述 llama.cpp的主要目標是能夠在…

【代碼隨想錄算法訓練營第37期 第十五天 | LeetCode226.翻轉二叉樹、101.對稱二叉樹 2】

代碼隨想錄算法訓練營第37期 第十五天 | LeetCode226.翻轉二叉樹、101.對稱二叉樹 2 一、226.翻轉二叉樹 解題代碼C&#xff1a; /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode() : …

【軟考中級 軟件設計師】數據結構

數據結構是計算機科學中一個基礎且重要的概念&#xff0c;它研究數據的存儲結構以及在此結構上執行的各種操作。在準備軟考中級-軟件設計師考試時&#xff0c;掌握好數據結構部分對于通過考試至關重要。下面是一些核心知識點概覽&#xff1a; 基本概念&#xff1a; 數據結構定義…

VBA_MF系列技術資料1-615

MF系列VBA技術資料1-615 為了讓廣大學員在VBA編程中有切實可行的思路及有效的提高自己的編程技巧&#xff0c;我參考大量的資料&#xff0c;并結合自己的經驗總結了這份MF系列VBA技術綜合資料&#xff0c;而且開放源碼&#xff08;MF04除外&#xff09;&#xff0c;其中MF01-0…

spring-boot集成slf4j(二)logback配置詳解

一、configuration 根節點&#xff1a;configuration&#xff0c;作為頂級標簽&#xff0c; 可以用來配置一些lockback的全局屬性&#xff0c;常見的屬性如下&#xff1a; &#xff08;1&#xff09;scan“true” &#xff1a;scan是否開啟自動掃描&#xff0c;監控配置文件更…

el-table 組件實現 “合并單元格 + N行數據小計” 功能

目錄 需求 - 要實現的效果初始代碼代碼升級&#xff08;可供多個表格使用&#xff09;CommonTable.vue 子組件 使用子組件1 - 父組件 - 圖1~圖3使用效果展示 使用子組件2 - 父組件 - 圖4使用效果展示 注意【代碼優化 - 解決bug】 需求 - 要實現的效果 父組件中 info 數據示例 …

內網安全之證書服務基礎知識

PKI公鑰基礎設施 PKI(Public Key Infrastructure)公鑰基礎設施&#xff0c;是提供公鑰加密和數字簽名服務的系統或平臺&#xff0c;是一個包括硬件、軟件、人員、策略和規程的集合&#xff0c;用來實現基于公鑰密碼體制的密鑰和證書的產生、管理、存儲、分發和撤銷等功能。企業…

Android Debug Bridge(ADB)命令使用

引言 Android Debug Bridge&#xff08;ADB&#xff09;是一套功能強大的命令行工具&#xff0c;它為Android開發者和高級用戶提供了與Android設備通信的能力。無論是進行應用開發、測試還是執行日常設備管理任務&#xff0c;ADB都是不可或缺的工具。本文將詳細介紹一些常用的…

element-plus:踩坑日記

el-table Q&#xff1a;有fixed屬性時&#xff0c;無數據時&#xff0c;可能出現底部邊框消失的bug 現象&#xff1a; 解決方法&#xff1a; .el-table__empty-block {border-bottom: 1px solid var(--el-table-border-color); } el-collapse 折疊面板 Q&#xff1a;標題上…

云平臺的安全能力提升解決方案

提升云平臺的安全能力是確保數據和服務安全的關鍵步驟。針對大型云平臺所面臨的云上安全建設問題&#xff0c;安全狗提供完整的一站式云安全解決方案&#xff0c;充分匹配云平臺安全管理方的需求和云租戶的安全需求。協助大型云平臺建設全網安全態勢感知、統一風險管理、統一資…

加強堆(大根堆)

way&#xff1a;看上去好像就是加了個indexMap記錄節點在數組heap中的下標&#xff0c;然后就是可以查到某個元素是否在堆里并且可以進行位置的調整&#xff0c;普通的堆是沒法知道元素是不是在的&#xff0c;只能彈堆頂元素&#xff0c;插入到堆尾這樣子。如果覺得heapSize有點…

PCIE協議-4-物理層邏輯模塊

4.1 簡介 物理層將事務層和數據鏈路層與用于鏈路數據交換的信令技術隔離開來。物理層被劃分為邏輯物理層和電氣物理層子模塊&#xff08;見圖4-1&#xff09;。 4.2 邏輯物理層子模塊 邏輯子模塊有兩個主要部分&#xff1a;一個發送部分&#xff0c;它準備從數據鏈路層傳遞過…