java webMvcConfig.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java webMvcConfig.java相关的知识,希望对你有一定的参考价值。

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;

import java.util.List;
import java.util.Locale;

@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {
	@Bean(name = "multipartResolver")
	public ExtStandardServletMultipartResolver multipartResolver() {
		ExtStandardServletMultipartResolver multipartResolver = new ExtStandardServletMultipartResolver();
		return multipartResolver;
	}
	
	@Bean
	public EmptyStringToNullModelAttributeMethodProcessor emptyStringToNullModelAttributeMethodProcessor() {
		EmptyStringToNullModelAttributeMethodProcessor p = new EmptyStringToNullModelAttributeMethodProcessor(true);
		return p;
	}

	@Bean
	public SpringSecurityDialect springSecurityDialect() {
		return new SpringSecurityDialect();
	}
	
	@Bean
	public LocaleResolver localeResolver() {
		SessionLocaleResolver slr = new SessionLocaleResolver();
		slr.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
		return slr;
	}

	@Bean
	public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
		HiddenHttpMethodFilter filter = new HiddenHttpMethodFilter();
		return filter;
	}

	@Bean
	public LocaleChangeInterceptor localeChangeInterceptor() {
		LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
		return lci;
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(localeChangeInterceptor());
		registry.addInterceptor(new RestApiInterceptor()).addPathPatterns("/api/services");
	}

	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
		argumentResolvers.add(emptyStringToNullModelAttributeMethodProcessor());
	}

	@Override
	public void addFormatters(FormatterRegistry registry) {
		registry.addConverterFactory(new EnumConverterFactory());
	}

}

以上是关于java webMvcConfig.java的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot零基础入门指南9--国际化

Java Switch

Java Math

Java 布尔运算

java [Java] Java常用代码#java

Java - 35 Java 实例