Spring Boot基礎教程7-web應用開發-模板引擎Thymeleaf

  • spring boot的web應用開發,是基於spring mvc

 

  • Spring boot 在spring默認基礎上,自動配置添加了以下特性:
  1. 包含了ContentNegotiatingViewResolver和BeanNameViewResolver beans。
  2. 對靜態資源的支持,包括對WebJars的支持。
  3. 自動註冊Converter,GenericConverter,Formatter beans。
  4. 對HttpMessageConverters的支持。
  5. 自動註冊MessageCodeResolver。
  6. 對靜態index.html的支持。
  7. 對自定義Favicon的支持。
  8. 主動使用ConfigurableWebBindingInitializer bean

 

  • 模板引擎的選擇

FreeMarker

Thymeleaf

Velocity (1.4版本之後棄用,Spring Framework 4.3版本之後棄用)

Groovy

Mustache

注:jsp應該儘量避免使用,原因如下:

  1. jsp只能打包爲:war格式,不支持jar格式,只能在標準的容器裏面跑(tomcat,jetty都可以)
  2. 內嵌的Jetty目前不支持JSPs
  3. Undertow不支持jsps
  4. jsp自定義錯誤頁面不能覆蓋spring boot 默認的錯誤頁面

 

  • Thymeleaf Demo

          <dependency>

              <groupId>org.springframework.boot</groupId>

              <artifactId>spring-boot-starter-thymeleaf</artifactId>

           </dependency>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章