①. web场景-web开发简介
①. 大多场景我们都无需自定义配置( Spring Boot provides auto-configuration for Spring MVC that works well with most applications)
内容协商视图解析器和BeanName视图解析器(Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans)
静态资源(包括webjars)(Support for serving static resources, including support for WebJars (covered later in this document)))
自动注册 Converter,GenericConverter,Formatter(Automatic registration of Converter, GenericConverter, and Formatter beans)
支持 HttpMessageConverters (后来我们配合内容协商理解原理)(Support for HttpMessageConverters (covered later in this document)
自动注册 MessageCodesResolver (国际化用)(Automatic registration of MessageCodesResolver (covered later in this document))
静态index.html 页支持(Static index.html support)
自定义 Favicon(Custom Favicon support (covered later in this document))
自动使用 ConfigurableWebBindingInitializer(DataBinder负责将请求数据绑定到JavaBean上))
Automatic use of a ConfigurableWebBindingInitializer bean (covered later in this document)
②. web场景-静态资源规则与定制化
①. 只要静态资源放在类路径下:called /static or /public or /resources or /META-INF/resources
访问 : 当前项目根路径/ + 静态资源名
②. 原理:静态映射/**
(请求进来,先去找Controller看能不能处理。不能处理的所有请求又都交给静态资源处理器。静态资源也找不到则响应404页面)
③. 代码展示:
@RestController public class staticController { //注意:我们在resources下是有d.jpg这个文件的 @GetMapping("/d.jpg") public String test1(){ return "abc"; } }
④. 也可以改变默认的静态资源路径,/static,/public,/resources, /META-INF/resources失效
spring: resources: static-locations: [classpath:/TANGZHI/]
⑤. 静态资源访问前缀
当前项目+static-path-pattern+静态资源名=静态资源文件夹下找
如下我们将通过http://localhost:8888/TANGZHI/a.jpg 进行访问页面
spring: mvc: static-path-pattern: /TANGZHI/** server: port: 8888