赞
踩
Spring boot 请求参数包含[]等特殊字符,导致无法接收问题
中括号[] 必须用%5B%5D转义,否则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 ; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。