开发环境windows下
1、自己新建一个类,最好是配置类config中,config包下
package com.ws.wssp.elec.business.config;
import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class TomcatConfig {
/**
* 解决异常信息:(允许参数有|{}[]特殊字符)
* java.lang.IllegalArgumentException:
* Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
* @return
*/
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
connector.setProperty("relaxedQueryChars", "|{}[]");
}
});
return factory;
}
}
linux部署环境
需要 编码—解码,后台java解码代码如下 :
URLDecoder.decode(”["xxx":"xxxxx123"]“, "UTF-8")
import java.net.URLEncoder;
try {
URLEncoder.encode("123","utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
前台编码如下:
//比如坐标: ruleForm.coordinate=[3,2,3]
let formData = JSON.parse(JSON.stringify(this.ruleForm)); //深度拷贝
formData.coordinate = window.encodeURI(formData.coordinate); //特殊字符处理