The main types of template engines that Spring Boot provides by default are as follows:
- Thymeleaf
- FreeMarker
- Velocity
- Groovy
- Mustache
Note: Avoid using JSP, JSP cannot implement various features of Spring Boot;
Integrate jsp
Tips:
1. Packaging method war
2. Import pom file:
<!-- 引入freeMarker的依赖包. -->
<!-- SpringBoot 核心组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
3, application.properties add
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
Note: Remember to create a corresponding directory
Integrate freemaker
1. In the pom file
<!-- 引入freeMarker的依赖包. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2. In the application.properties file
spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
#spring.freemarker.prefix=
#spring.freemarker.request-context-attribute=
#spring.freemarker.settings.*=
spring.freemarker.suffix=.ftl
spring.freemarker.template-loader-path=classpath:/templates/#建立目录
Others are written as they are, OK
Summary:
I have just come into contact with springboot. At present, it feels similar to spring. The so-called ignorant is fearless (that's what I said, it's wrong, I'll talk about it later, it's always right once)