SpringBoot使用thymeleaf
thymeleaf音译:塞姆理符
1.新建SpringBoot项目,选择thymeleaf依赖,会自动导入
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
- 1
- 2
- 3
- 4
2.创建POJO
package com.cvsea;public class Person {private String name;private Integer age;public Person(String P_Name,Integer P_Age){this.name=P_Name;this.age=P_Age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
3.创建演示页面,thymeleaf模板引擎页面放在src/main/resources/templates下。
index.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>
</head>
<body><div><h3>访问model</h3><span th:text="${singlePeson.name}"></span>
</div><div th:if="${not #lists.isEmpty(people)}"><h3>访问列表</h3><ul><li th:each="person:${people}"><span th:text="${person.name}"></span><span th:text="${person.age}"></span><button th:onclick="'getName(\''+${person.name}+'\')'">获取名字</button></li></ul>
</div>
<script th:inline="javascript">
var single=[[${singlePeson}]]
console.log(single.name+"/"+single.age);
function getName(name)
{console.log(name);
}
</script>
</body>
</html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
4.注入数据
package com.cvsea;import java.util.ArrayList;
import java.util.List;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 Learning1Application {@RequestMapping("/")public String hello(Model model){Person person=new Person("pxs",26);model.addAttribute("singlePeson",person);List<Person> people=new ArrayList<Person>();people.add(new Person("pxs",26));people.add(new Person("nxy",26));people.add(new Person("lgp",26));model.addAttribute("people",people);return "index"; }public static void main(String[] args) {SpringApplication.run(Learning1Application.class, args);}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
5.运行效果
转载自:https://blog.csdn.net/JHYPXS/article/details/78080231
SpringBoot使用thymeleaf相关推荐
- spring boot构建基础版web项目(一)springboot、thymeleaf控制层基础构
原文作者:弥诺R 原文地址:http://www.minuor.com/147852147/article 转载声明:转载请注明原文地址,注意版权维护,谢谢! 写前说明 根据个人在各篇博文中看到的信息 ...
- thymeleaf 使用页面报错_异常处理-SpringBoot中thymeleaf对应前台页面大于号\小于号使用问题...
浏览器报错信息: There was an unexpected error (type=Internal Server Error, status=500). Exception parsing d ...
- thymeleaf依赖_玩转SpringBoot集成 Thymeleaf 模版引擎
随着互联网技术的发展,在前后端分离开发模式已经逐渐成为主流的今天,前后端技术的划分也越来越清晰,社会分工进一步细化,职业岗位也更加细分,慢慢开始就有了前端攻城狮和后端攻城狮,技术也进一步细分,出现了以 ...
- 玩转springboot:thymeleaf模板引擎入门程序
一.前言 常用的模板引擎有:JSP.Velocity.Freemarker.Thymeleaf 但是,Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎.而且,语法更简单,功 ...
- 九、SpringBoot集成Thymeleaf模板引擎
Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:"赛母李府",大部分中国 ...
- Springboot整合thymeleaf模板
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- 基于springboot的生鲜门店配送管理系统(idea+springboot+html+thymeleaf)
一.系统简介 本项目采用idea工具开发,html+springboot+mybatis+jquery+thymeleaf技术编写,数据库采用的是mysql,navicat开发工具. 系统一共分为5个 ...
- SpringBoot整合Thymeleaf模板引擎以及静态资源的访问
SpringBoot整合Thymeleaf模板引擎静态资源访问的配置 Thymeleaf是一个现代服务器端Java模板引擎,适用于Web和独立环境,能够处理HTML,XML,JavaScript,CS ...
- SpringBoot整合thymeleaf之模糊查询操作模块
SpringBoot整合thymeleaf之模糊查询操作模块 引言 1.一般情况下,Mybatis的模糊查询操作 模糊查询操作 2.在实战中的模糊查询操作 web页面提交数据 <form act ...
- 【Springboot学习笔记】SpringBoot+Mybatis+Thymeleaf+Layui数据表单从零开始实现按条件模糊分页查询的方法
[Springboot学习笔记]SpringBoot+Mybatis+Thymeleaf+Layui数据表单从零开始实现按条件模糊分页查询的方法 目录 1.搭建环境 1.1直接从网上下载SpringB ...
最新文章
- 1120. Friend Numbers (20)
- ubuntu MySQL Oracle_Oracle 与 MySql 区别
- 十四个值得推荐的个人提升方法
- P2754 [CTSC1999]家园 / 星际转移问题(网络流)
- 华为p10和p10plus区别_华为p10和p10plus哪个好 华为p10与p10plus区别对比【图文】
- 【毕业设计】JAVA文件压缩与解压缩实践(源代码+论文)
- 虚拟机镜像xp\win7\win10\win8\win2003,免安装系统,下载即用
- 腾讯推出移动端动画组件PAG,释放设计生产力!
- IDEA社区版下载安装
- 如何安装biopython_Biopython安装
- GPGPU基础(五):使用compute shader进行通用计算及示例
- mysql先进后出_栈、队列中“先进先出”,“后进先出”的含义
- 【PaddleHub模型贡献】一行代码实现海洋生物识别
- 红军协同对抗蓝军问题
- R语言:逆变换法生成随机数
- 心灵鸡汤1------让人奋进的五句话
- 少儿编程培训 python
- vscode 调整行间距
- Fitting ellipse
- xpath 解析,实战链家二手房项目
热门文章
- spring @order控制对象的顺序
- centos7 卸载Qt5
- 邮件作为证据如何提交_电子邮件作为证据应该怎么提交?
- yum 转mysql_centos下彻底删除MYSQL 和重新安装MYSQL(转)
- linux反调试代码,linux反调试方法
- tms570 can 接收大量数据_CAN通讯系列--AUTOSAR架构的CAN Interface7
- vue渲染html失败,Vue ssr失败,渲染的html为undefined
- java如何知道需导入哪个包_怎么知道缺少哪个jar包,求助!!!
- 标签页如何用php静态显示,php使用标签替换的方式生成静态页面
- php退出页面父元素,jQuery中弹出iframe内嵌页面元素到父页面并全屏化的实例代码...