这里使用的是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. Qt样式表之三:实现按钮三态效果的三种方法

    按钮的三态,指的是普通态.鼠标的悬停态.按下态.Qt中如果使用的是默认按钮,三态的效果是有的,鼠标放上去会变色,点击的时候有凹陷的效果. 但是如果自定义按钮实现三态效果有三种方法,一种是设置背景图,主 ...

  2. STM32CUBEMX使用注意:

    一 注意堆栈大小,简单来说,栈空间用于局部变量空间(size=0x400一般够用),堆(size=0x200一般够用)空间用于 alloc 或者 malloc函数动态申请变量空间

  3. 深入理解spark streaming

    spark streaming是建立在spark core之上的,也就说spark streaming任务最终执行还是依赖于RDD模型.在转化成最终的RDD模型执行前,spark streaming主 ...

  4. 【前端】jQurey Plugin

    ; (function ($, window, document, undefined) { "use strict"; var defaults = { name: " ...

  5. 基于ABP的Easyui admin framework正式开放源代码

    下载&反馈:http://www.webplus.org.cn v1.0 (2016/9/21) EF6+MVC5+API2+Easyui1.4.2开发 后台管理不使用iframe,全ajax ...

  6. mysql索引命中规则

    转于:https://blog.csdn.net/claram/article/details/77574600 首先明确:为什么要用联合索引? 对于查询语句“SELECT E.* FROM E WH ...

  7. 关于java的Long 类型到js丢失精度的问题

    写代码碰到一个bug, 现象是 后台Java返回的18位的Long类型的数据,到前台丢失了精度.  查了一下,原因是 java的Long类型是18位, 而 js的Long类型(虽然没有明确定义的Lon ...

  8. bootstrap CSS表单、按钮和字体图标

    基础表单   <form role="form">     <div class="form-group">         <l ...

  9. IDEA一些设置

    1. 设置字体为Consolas,Size:16, Line spacing: 1.1 2. 设置智能提示大小写不敏感 在设置中搜索sense, 找到配置节点 Editor->General-& ...

  10. VBA 连接sql server的用法

    cnnstr = "Provider=sqloledb;Data Source=192.211.21.8;Initial Catalog=pub;UID=账号;PWD=密码" VB ...