1.加載靜態資源
1.所有 /webjars/** ,都去 classpath:/META-INF/resources/webjars/ 找資源;
2)、”/**” 訪問當前項目的任何資源,都去(靜態資源的文件夾)找映射
localhost:8080/abc === 去靜態資源文件夾裏面找abc
3)、歡迎頁; 靜態資源文件夾下的所有index.html頁面;被”/**”映射;
localhost:8080/ 找index頁面
4)、所有的 **/favicon.ico 都是在靜態資源文件下找;
“classpath:/META‐INF/resources/”,
“classpath:/resources/”,
“classpath:/static/”,
“classpath:/public/”
“/”:當前項目的根路徑
2.模板引擎
目前各種的模板引擎:JSP、Velocity、Freemarker、Thymeleaf
SpringBoot推薦的Thymeleaf;
語法更簡單,功能更強大;
1、引入thymeleaf;
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring‐boot‐starter‐thymeleaf</artifactId>
2.1.6
</dependency>
切換thymeleaf版本
<properties>
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
<!‐‐ 佈局功能的支持程序 thymeleaf3主程序 layout2以上版本 ‐‐>
<!‐‐ thymeleaf2 layout1‐‐>
<thymeleaf‐layout‐dialect.version>2.2.2</thymeleaf‐layout‐dialect.version>
</properties>
2、Thymeleaf使用
只要我們把HTML頁面放在classpath:/templates/,thymeleaf就能自動渲染;
使用:
1、導入thymeleaf的名稱空間
2、使用thymeleaf語法;
3、語法規則
1)、th:text;改變當前元素裏面的文本內容;
th:任意html屬性;來替換原生屬性的值
3、SpringMVC自動配置
- Spring MVC auto-configuration
Spring Boot 自動配置好了SpringMVC
以下是SpringBoot對SpringMVC的默認配置:(WebMvcAutoConfiguration)
4.國際化
1)、編寫國際化配置文件;
2)、使用ResourceBundleMessageSource管理國際化資源文件
3)、在頁面使用fmt:message取出國際化內容
步驟:
1)、編寫國際化配置文件,抽取頁面需要顯示的國際化消息