Web Development Auto-configuration class: Org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
1.1. Automatic configuration of the Viewresolver
The configuration of the View Mvcproperties object:
Org.springframework.boot.autoconfigure.web.WebMvcProperties.View
1.2. Configure static resource 1.2.1 automatically. Enter rule to/
If the rule to enter SPRINGMVC is/, the path to the default static resource for Spring boot is:
spring.resources.static-locations=classpath:/meta-inf/resources/,classpath:/resources/,classpath:/static/, classpath:/public/
Test:
1.2.2. When entering a rule of *.xxx or not specifying a static file path
Placing static resources in the static directory under WebApp can be accessed by address:
Test:
1.3. Custom Message Converters
To customize the message converter, simply add the message Converter's @bean to the spring container in the @configuration class, and it will be automatically added to the container by spring boot.
@Bean public stringhttpmessageconverter stringhttpmessageconverter () { Stringhttpmessageconverter Converter new stringhttpmessageconverter (Charset.forname (" UTF-8 " )); return Converter;}
Default configuration:
1.4. Customizing the SPRINGMVC Configuration
There are times when we need to configure SPRINGMVC instead of using the default, such as adding an interceptor, which can be extended by inheriting webmvcconfigureradapter and then overriding the methods in the parent class.
1 import Java.nio.charset.Charset;2 3 import java.util.List;4 5 6 7 import javax.servlet.http.HttpServletRequest;8 9 import Javax.servlet.http.HttpServletResponse;Ten One A - import org.springframework.context.annotation.Configuration; - the import Org.springframework.http.converter.HttpMessageConverter; - - import Org.springframework.http.converter.StringHttpMessageConverter; - + import Org.springframework.web.servlet.HandlerInterceptor; - + import Org.springframework.web.servlet.ModelAndView; A at import org.springframework.web.servlet.config.annotation.InterceptorRegistry; - - import Org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - - - in@Configuration//affirm that this is a configuration - to Public classMysrpingmvcconfig extends webmvcconfigureradapter{ + - the * //Custom Interceptors $ Panax Notoginseng @Override - the Public voidaddinterceptors (Interceptorregistry registry) { + AHandlerinterceptor Handlerinterceptor =NewHandlerinterceptor () { the + @Override - $ Publicboolean prehandle (httpservletrequest request, httpservletresponse response, Object handler) $ - throws Exception { - theSystem. out. println ("Custom Interceptors ..... ....."); - Wuyi return true; the - } Wu - About $ @Override - - Public voidPosthandle (httpservletrequest request, httpservletresponse response, Object handler, - A Modelandview Modelandview) throws Exception { + the - $ } the the the the @Override - in Public voidaftercompletion (httpservletrequest request, httpservletresponse response, Object handler, the the Exception ex) throws Exception { About the } the the }; + -Registry.addinterceptor (Handlerinterceptor). Addpathpatterns ("/**"); the Bayi } the the - - //the second method of customizing the message converter the the @Override the the Public voidConfiguremessageconverters (listconverters) { - theStringhttpmessageconverter converter =NewStringhttpmessageconverter (Charset.forname ("UTF-8")); the the Converters.add (converter);94 the } the the 98 About}
Spring Boot web Development