Spring Boot Web开发中Thymeleaf模板引擎的使用
这里使用的是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模板引擎的使用的更多相关文章
- Spring Boot Web开发与thymeleaf模板引擎
简介: 使用Springboot应用,选中需要的模块, Spring已经默认将场景配置好了,只需在配置文件中少量配置就可以运行起来 自己编写业务代码 自动配置原理 这个场景Springboot帮我们配 ...
- Spring Boot 2.0 整合Thymeleaf 模板引擎
本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎 1. 创建项目 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序 3. 填写项目配 ...
- Springboot 系列(五)Spring Boot web 开发之静态资源和模版引擎
前言 Spring Boot 天生的适合 web 应用开发,它可以快速的嵌入 Tomcat, Jetty 或 Netty 用于包含一个 HTTP 服务器.且开发十分简单,只需要引入 web 开发所需的 ...
- SpringBoot Web开发(4) Thymeleaf模板与freemaker
SpringBoot Web开发(4) Thymeleaf模板与freemaker 一.模板引擎 常用得模板引擎有JSP.Velocity.Freemarker.Thymeleaf SpringBoo ...
- Springboot 系列(七)Spring Boot web 开发之异常错误处理机制剖析
前言 相信大家在刚开始体验 Springboot 的时候一定会经常碰到这个页面,也就是访问一个不存在的页面的默认返回页面. 如果是其他客户端请求,如接口测试工具,会默认返回JSON数据. { &quo ...
- Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客
==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...
- Springboot 系列(六)Spring Boot web 开发之拦截器和三大组件
1. 拦截器 Springboot 中的 Interceptor 拦截器也就是 mvc 中的拦截器,只是省去了 xml 配置部分.并没有本质的不同,都是通过实现 HandlerInterceptor ...
- Spring Boot 2.0 整合 FreeMarker 模板引擎
本篇博文将和大家一起使用Spring Boot 2.0 和FreeMarker 模板引擎整合实战. 1. 创建新的项目 2. 填写项目配置信息 3. 勾选web 模块 4. 勾选freemarker模 ...
- Spring Boot Web 开发注解篇
本文提纲 1. spring-boot-starter-web 依赖概述 1.1 spring-boot-starter-web 职责 1.2 spring-boot-starter-web 依赖关系 ...
随机推荐
- 多线程 synchronized锁定当前对象
synchronized(this) 和synchronized一样,都是锁定当前对象. public class Task { synchronized public void otherMetho ...
- Codeforces 1107E(区间dp)
用solve(l, r, prefix)代表区间l开始r结束.带了prefix个前缀str[l](即l前面的串化简完压缩成prefix-1个str[l],加上str[l]共有prefix个)的最大值. ...
- ACM_LRU页面置换算法
LRU页面置换算法 Time Limit: 2000/1000ms (Java/Others) Problem Description: sss操作系统没听课, 这周的操作系统作业完全不会, 你能帮他 ...
- [转]Java中Date转换大全,返回yyyy-MM-dd的Date类型
/** * 获取现在时间,这个好用 * * @return返回长时间格式 yyyy-MM-dd HH:mm:ss */ public static Date getSqlDate() { Date s ...
- (023) 关于51单片机的A5指令
可看见一篇讲51单片机加密的文章这么讲: [加密方法:在A5后加一个二字节或三字节操作码,因为所有反汇编软件都不会反汇编A5指令,造成正常程序反汇编乱套,执行程序无问题仿制者就不能改变你的源程序.] ...
- [已读]编写高质量代码 改善JavaScript程序的188个建议
吐槽一万遍,买的最后悔的一本,没有之一,大量篇幅抄袭<高性能javascript>,我记得还有部分抄袭<javascript精粹>,<javascript模式>有没 ...
- D. The Door Problem 带权并查集
http://codeforces.com/contest/776/problem/D 注意到每扇门都有两个东西和它连接着,那么,如果第i扇门的状态是1,也就是已经打开了,那么连接它的两个按钮的状态应 ...
- 浅析 Spark Shuffle 内存使用
在使用 Spark 进行计算时,我们经常会碰到作业 (Job) Out Of Memory(OOM) 的情况,而且很大一部分情况是发生在 Shuffle 阶段.那么在 Spark Shuffle 中具 ...
- PropTypes 和组件参数验证
我们来了到了一个非常尴尬的章节,很多初学的朋友可能对这一章的知识点不屑一顾,觉得用不用对程序功能也没什么影响.但其实这一章节的知识在你构建多人协作.大型的应用程序的时候也是非常重要的,不可忽视. 都说 ...
- C# 控制台如何播放音频文件
OK,先看下代码: using System.Reflection; using System.Media; namespace ThePlay { class Program { static vo ...