type
status
date
slug
summary
tags
category
icon
password
@ZZHow(ZZHow1024)
现象
- SpringBoot 项目中路径参数带“/”导致 404 错误

解决方法1
- RFC3986 文档规定,URL 中只允许包含英文字母(a-z,A-Z)、数字(0-9)以及"-_. ~" 4 个特殊字符
- Base64 编码包括小写字母 a-z、大写字母 A-Z、数字 0-9、符号"+"和"/"共 64 个字符
- 因此,可以在 URL 将"/"替换为"-",将"+"替换为"_",接收到字符串后再反过来将"-"替换为"/",将"_"替换为"+"
- 前端:
- 后端:
解决方法2
- 前端将路径参数进行 URL 编码
- 再次尝试访问,Tomcat 报 HTTP Status 400 – Bad Request 错误
- 原因:Tomcat 默认不支持转义

- 修改启动类,加一个系统参数,重写
WebMvcConfigurerAdapter
的configurePathMatch
方法