All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.luues.core.webMvcConfigurer.MyWebAppConfigurer Maven / Gradle / Ivy

There is a newer version: 2.0.1.RELEASE
Show newest version
package com.luues.core.webMvcConfigurer;

import com.luues.core.config.BeanConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.UrlPathHelper;

import java.util.List;


@Configuration(value = "application_bean_configurer")
public class MyWebAppConfigurer implements WebMvcConfigurer {

    private final BeanConfig beanConfig = BeanConfig.getBeanConfig();

    /**
     * 静态资源路径配置
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("/**")
                .addResourceLocations(
                        "classpath:/META-INF/resources/",
                        "classpath:/resources/",
                        "classpath:/static/",
                        "classpath:/public/")
                .setCachePeriod(60 * 60 * 24 * 30)
                .resourceChain(true);
    }
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        UrlPathHelper urlPathHelper = new UrlPathHelper();
        urlPathHelper.setUrlDecode(beanConfig.isPathVariableUrlDecode());
        configurer
                // configurer.setUseSuffixPatternMatch(false)表示设计人员希望系统对外暴露的URL不会识别和匹配.*后缀:设置是否是后缀模式匹配,如“/user”是否匹配/user.*,默认真即匹配;
                .setUseSuffixPatternMatch(beanConfig.isPathVariableUseSuffixPatternMatch())
                // configurer.setUseTrailingSlashMatch(true)表示系统不区分URL的最后一个字符是否是斜杠/:设置是否自动后缀路径模式匹配,如“/user”是否匹配“/user/”,默认真即匹配
                .setUseTrailingSlashMatch(beanConfig.isPathVariableUseTrailingSlashMatch())
                .setUrlPathHelper(urlPathHelper);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy