Spring Boott基础教程六:web应用开发-模板引擎

目录

1、简介

2、模板引擎的选择

3、FreeMarker Demo

4、Thymeleaf Demo


1、简介

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

2、模板引擎的选择

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 默认的错误页面

3、FreeMarker Demo

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

4、Thymeleaf Demo

<dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

 5、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

 

 

 

 

 

 

 

发布了632 篇原创文章 · 获赞 758 · 访问量 51万+

猜你喜欢

转载自blog.csdn.net/songzi1228/article/details/104015681