这里使用的是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

Spring Boot Web开发中Thymeleaf模板引擎的使用的更多相关文章

  1. Spring Boot Web开发与thymeleaf模板引擎

    简介: 使用Springboot应用,选中需要的模块, Spring已经默认将场景配置好了,只需在配置文件中少量配置就可以运行起来 自己编写业务代码 自动配置原理 这个场景Springboot帮我们配 ...

  2. Spring Boot 2.0 整合Thymeleaf 模板引擎

    本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎 1. 创建项目 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序 3. 填写项目配 ...

  3. Springboot 系列(五)Spring Boot web 开发之静态资源和模版引擎

    前言 Spring Boot 天生的适合 web 应用开发,它可以快速的嵌入 Tomcat, Jetty 或 Netty 用于包含一个 HTTP 服务器.且开发十分简单,只需要引入 web 开发所需的 ...

  4. SpringBoot Web开发(4) Thymeleaf模板与freemaker

    SpringBoot Web开发(4) Thymeleaf模板与freemaker 一.模板引擎 常用得模板引擎有JSP.Velocity.Freemarker.Thymeleaf SpringBoo ...

  5. Springboot 系列(七)Spring Boot web 开发之异常错误处理机制剖析

    前言 相信大家在刚开始体验 Springboot 的时候一定会经常碰到这个页面,也就是访问一个不存在的页面的默认返回页面. 如果是其他客户端请求,如接口测试工具,会默认返回JSON数据. { &quo ...

  6. Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客

    ==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...

  7. Springboot 系列(六)Spring Boot web 开发之拦截器和三大组件

    1. 拦截器 Springboot 中的 Interceptor 拦截器也就是 mvc 中的拦截器,只是省去了 xml 配置部分.并没有本质的不同,都是通过实现 HandlerInterceptor ...

  8. Spring Boot 2.0 整合 FreeMarker 模板引擎

    本篇博文将和大家一起使用Spring Boot 2.0 和FreeMarker 模板引擎整合实战. 1. 创建新的项目 2. 填写项目配置信息 3. 勾选web 模块 4. 勾选freemarker模 ...

  9. Spring Boot Web 开发注解篇

    本文提纲 1. spring-boot-starter-web 依赖概述 1.1 spring-boot-starter-web 职责 1.2 spring-boot-starter-web 依赖关系 ...

随机推荐

  1. class JsonItemExporter(BaseItemExporter):

    class JsonItemExporter(BaseItemExporter):这个类的实现和几年前的实现有了点小变化,主要就是是否添加换行

  2. C++伪函数

    #include <iostream> void say_hello() { std::cout << "hello world !" << s ...

  3. C++11六大函数(构造函数,移动构造函数,移动赋值操作符,复制构造函数,赋值操作符,析构函数)

    在C++中,有三大函数复制控制(复制构造函数,赋值操作符,析构函数),而在C++11中,加入了移动构造函数,移动赋值操作符.我就斗胆将他们命名为六大函数好了. 一.构造函数 c++primer中说过: ...

  4. JavaScript中简单排序总结

    JavaScript中简单排序总结 冒泡排序 经典排序算法, 双重for循环 在第二个for循环的时候, j < arr.len -1 -i , 这一步的优化很重要 function bullS ...

  5. lavarel功能总结

    详细可参见笔记:laraval学习笔记(二) 路由 route 绑定模型,绑定参数 模版 blade .blade.php后缀,有laravel自己的模版语法 模型 model 如果用create创建 ...

  6. RHEL6.4上Samba/NFS服务器简单配置

    近期在RHEL6.4上尝试搭建一个NAS,底层使用XFS文件系统,对外主要提供samba协议和NFS协议共享,这里把主要步骤记录下来. 环境:RHEL6.4,IP:192.168.50.117 1.关 ...

  7. Javascript中setTimeout()以及clearTimeout( )的使用

    setTimeout setTimeout( ) 是属于 window 的 method, 这是用来设定一个时间,时间到了, 就会执行一个指定的 方法.练习一:等候三秒才执行的 alert( )set ...

  8. react基础语法(二)常用语法如:样式 ,自定义属性,常用表达式

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. SAP CRM点了附件的超链接后报错的处理方式

    SAP CRM系统里,点击了附件的这些超链接后,如果是文本文件,会在浏览器里打开.如果是其他类型的文件,会弹出下载对话框. 然而最近我工作时遇到一个问题,点击超链接后,总是弹出Logon failed ...

  10. (转)编码剖析Spring依赖注入的原理

    http://blog.csdn.net/yerenyuan_pku/article/details/52834561 Spring的依赖注入 前面我们就已经讲过所谓依赖注入就是指:在运行期,由外部容 ...