package com.hzs.common.core.config;


import com.hzs.common.core.filter.TrimFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;

/**
 * description: 通过FilterRegistrationBean注册自定义过滤器TrimFilter
 * @author: sui q
 * @time: 2023/4/3 14:05
 * @classname: WebBindingInitializerConfiguration
 * @package_name: com.hzs.gateway.config
 * version 1.0.0
 */
@Configuration
public class FilterConfig {
    /**
     * 注册去除参数头尾空格过滤器
     */
    @Bean
    public FilterRegistrationBean trimFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new TrimFilter());
        registration.addUrlPatterns("/**");
        registration.setName("paramsFilter");
        registration.setOrder(Integer.MAX_VALUE-1);
        return registration;
    }
}
