首页 > 编程语言 > 详细

Springboot整合thymeleaf

时间:2019-05-08 23:02:41      阅读:138      评论:0      收藏:0      [点我收藏+]

1、创建maven项目

具体的配置如下

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
  </parent>
  <groupId>com.zhu</groupId>
  <artifactId>09-spring-boot-rhemyleaf</artifactId>
  <version>0.0.1-SNAPSHOT</version>

2、在pom文件中添加坐标并修改版本

<!-- 修改jdk版本 -->
  <properties>
  	<java.version>1.7</java.version>
  	<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
  	<thymeleaf-layout-dailet.version>2.0.4</thymeleaf-layout-dailet.version>
  </properties>
  
  <dependencies>
  <!-- springboot启动器 -->
 	 <dependency>
  		<groupId>org.springframework.boot</groupId>
  		<artifactId>spring-boot-starter-web</artifactId>
 	 </dependency>
  <!-- springboot启动器 -->
 	 <dependency>
  		<groupId>org.springframework.boot</groupId>
  		<artifactId>spring-boot-starter-thymeleaf</artifactId>
 	 </dependency>
 	 
 	 
  </dependencies>

3、编写Controller类

package com.zhu.controller;
@Controller
public class FirstController {
	
	@RequestMapping("/show")
	public String showView(Model model) {
		model.addAttribute("msg", "first work");
		return "index";
	}
}

4、在classpath/目录下,即src/main/resourses目录下创建文件夹templates,并在该文件下创建HTML文件index.html

!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>rhymeleaf入门</title>
</head>
<body>
	<span th:text="Hello"></span>
	<hr/>
	<span th:text="${msg}"></span>
	
</body>
</html>

5、先写启动类即可

6、整个pom配置文件(因打错单词运行出错过)

技术分享图片
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
  </parent>
  <groupId>com.zhu</groupId>
  <artifactId>09-spring-boot-rhemyleaf</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <!-- 修改jdk版本 -->
  <properties>
      <java.version>1.7</java.version>
      <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
      <thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version>
  </properties>
  
  <dependencies>
  <!-- springboot启动器 -->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
  <!-- springboot启动器 -->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-thymeleaf</artifactId>
      </dependency>
      
      
  </dependencies>
  
</project>
View Code

 

Springboot整合thymeleaf

原文:https://www.cnblogs.com/happyeven/p/10835160.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!