- 前言
- 对字符进行转义
- 修改tomcat 配置
前言
Spring boot 请求参数包含[]等特殊字符,导致无法接收问题
对字符进行转义
中括号[] 必须用%5B%5D转义,否则tomcat无法解析,回抛出不合法字符异常,不会进入控制器
修改tomcat 配置
package cn.com.cosmagn.wms.config;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Author: hrd
* @CreateTime: 2024/3/8 13:56
* @Description:
*/
@Configuration
public class Config {
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory (){
// 修改内置的 tomcat 容器配置
TomcatServletWebServerFactory tomcatServlet = new TomcatServletWebServerFactory();
tomcatServlet .addConnectorCustomizers(
(TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "[]")
);
return tomcatServlet ;
}
}