springBoot整合模板引擎(jsp,freemarker,thymeleaf)


1.jsp

#SpringMvc配置
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
<!-- spring boot jsp -->
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>javax.servlet-api</artifactId>
	<scope>provided</scope>
</dependency>
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
</dependency>
<!-- tomcat的支持.-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
	<scope>provided</scope>
</dependency>
<dependency>
	<groupId>org.apache.tomcat.embed</groupId>
	<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>JSP</title>
</head>
<body>
<h1>JSP</h1>
11
</body>
</html>

2.freemarker

<!-- spring boot freemarker -->
<!--<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
#Freemarker
#spring.freemarker.template-loader-path=classpath:/templates/
#spring.freemarker.suffix=.html
<html xmlns="http://www.w3.org/1999/html">
<head>
<title>Freemarker</title>
</head>
<body>
<h1>Freemarker</h1>
${hello}
</body>
</html>

3.thymeleaf

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>-->
#Thymeleaf
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8" />
    <title></title>
</head>
<body>
<h1>Hello World</h1>
<span th:text="${hello}"></span>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/m0_37499059/article/details/80241190