[springboot] render web page

Posted by sureshp on Mon, 30 Mar 2020 22:53:41 +0200

Spring Boot provides the following template engines for default configuration:

  • Thymeleaf
  • FreeMarker
  • Velocity
  • Groovy
  • Mustache

Note: avoid using JSP, JSP can't realize many features of Spring Boot;

Integrate jsp

Tips:
1. Packing method war
2. To import a pom file:

<!-- Introduce freeMarker Dependency package. -->
<!-- SpringBoot Core components -->
<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 adding

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

Note: remember to create a directory accordingly

Integrate freemaker

1. In pom file

<!-- Introduce freeMarker Dependency package. -->
<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/#create directory

Others are written as before, OK

Summary:
springboot has just been contacted. It feels like spring at present. The so-called ignorant people are fearless (that is to say, it's wrong. In the future, it will be right one time)

Topics: Spring FreeMarker JSP Tomcat