这里使用的是idea

1.新建Spring Boot项目

  File-->New-->Project...,然后选择左边的Spring Initializr-->Next,可根据自己的需求修改,也可默认,-->Next,选择依赖项。-->Template Engines中的Thymeleaf-->Next-->finish。

2.建立实体类

package com.example.thymeleaf.entity;

public class Person {
private String name;
private Integer age; public Person(){
super();
} public Person(String name,Integer age){
super();
this.age=age;
this.name=name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}

2.在ThymeleafApplication.java文件中,修改如下

package com.example.thymeleaf;

import com.example.thymeleaf.entity.Person;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@SpringBootApplication
public class ThymeleafApplication { @RequestMapping("/")
public String index(Model model){
Person single = new Person("aa",11);
model.addAttribute("singlePerson",single);
return "index";
} public static void main(String[] args) {
SpringApplication.run(ThymeleafApplication.class, args);
}
}

3.在resource-->templates下建立index.html文件,内容如下。

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello World!</title>
</head>
<body>
<p th:text="${singlePerson.name}"></p>
</body>
</html>

Thymeleaf是一个Java类库,我的理解是类似于JSP文件也类似与Anjularjs。如果想了解详解内容请到官网查看:http://www.thymeleaf.org/

4.浏览器中输入localhost:8080显示内容如下

aa

最新文章

  1. java.net.UnknownHostException: promote.cache-dns.local: unknown error
  2. Python基础篇【第2篇】: Python内置函数(一)
  3. 关于oracle 11g 64位与 32位的 plsql、及其他32位应用程序共存的问题
  4. [转]SQL:JOIN用法
  5. andirod
  6. php加载memcache
  7. php文件上传之单文件上传
  8. (转载)JavaScript中定义变量
  9. 关于下拉刷新你是否真的非常理解还是只会搬砖?附 Android 实例子源代码文件下载地址380个合集
  10. 全栈project师?给把瑞士军刀你去砍鬼子好不好!?
  11. HDU 2069 Coin Change
  12. Linux下的下载工具介绍----aria2
  13. mongodb 性能提高之利用索引, 待续
  14. ural1090 In the Army Now
  15. Java变量和对象的作用域
  16. hibulder中使用git教程
  17. asp.net core 系列 15 中间件
  18. checkout 多选 全选(亲测有效)
  19. Ngnix配置
  20. mysql5.7.23手动配置安装windows版

热门文章

  1. linux之用户态和内核态
  2. 点击a标签的子元素不跳转 ,阻止默认行为
  3. Codeforces 1144G(dp)
  4. Four Segments CodeForces - 846C
  5. ACM_LRU页面置换算法
  6. (转)生产者/消费者问题的多种Java实现方式
  7. Spark-SQL连接Hive
  8. 3个解析url的php函数
  9. js 获取最后一个字符
  10. spring boot druid mybatis多数据源