web應用開發-模板引擎JSP
阿新 • • 發佈:2019-01-07
- spring boot的web應用開發,是基於spring mvc
- Spring boot 在spring預設基礎上,自動配置添加了以下特性:
- 包含了ContentNegotiatingViewResolver和BeanNameViewResolver beans。
- 對靜態資源的支援,包括對WebJars的支援。
- 自動註冊Converter,GenericConverter,Formatter beans。
- 對HttpMessageConverters的支援。
- 自動註冊MessageCodeResolver。
- 對靜態index.html的支援。
- 對自定義Favicon的支援。
- 主動使用ConfigurableWebBindingInitializer bean
- 模板引擎的選擇
FreeMarker
Thymeleaf
Velocity (1.4版本之後棄用,Spring Framework 4.3版本之後棄用)
Groovy
Mustache
注:jsp應該儘量避免使用,原因如下:
- jsp只能打包為:war格式,不支援jar格式,只能在標準的容器裡面跑(tomcat,jetty都可以)
- 內嵌的Jetty目前不支援JSPs
- Undertow不支援jsps
- jsp自定義錯誤頁面不能覆蓋spring boot 預設的錯誤頁面
- Jsp Demo
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
新增配置引數:
spring.mvc.view.prefix: /WEB-INF/templates/
spring.mvc.view.suffix: .jsp