The parameter boundary space filter of the get method

Article Directory

Ideas:

  • This method is for get requests. The parameters of the get request are all spliced ​​in the url. The idea should be to get the full path of the url and then pass? Split out the parameter part,? name=as&age=12, after that, split & to split different parameters. For different parameters, split= can get the parameter name and parameter value.
    The idea is to get the value and remove the spaces on both sides of the value (whether it is in Chinese or English) and
    then re-splicing the url

method

@ControllerAdvice(basePackages = {
    
    "com.sss"})
public class FilterBlankController {
    
    
    @InitBinder
    public void initBinder(WebDataBinder binder) {
    
    
        // 创建 String trim 编辑器
        // 构造方法中 boolean 参数含义为如果是空白字符串,是否转换为null
        // 即如果为true,那么 " " 会被转换为 null,否者为 ""
        StringTrimmerEditor propertyEditor = new StringTrimmerEditor(false);
        // 为 String 类对象注册编辑器
        binder.registerCustomEditor(String.class, propertyEditor);
    }
}

Guess you like

Origin blog.csdn.net/wangleisuiqiansuiyue/article/details/110949379