踩坑——纪实

开发踩坑纪实

  • 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.mzph.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;它准备从数据链路层传递过…