SpringBoot使用thymeleaf案例
1 编写application.properties文件
spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF- spring.thymeleaf.servlet.content-type=text/html #springboot 官方文档建议我们关闭thymeleaf的缓存 spring.thymeleaf.cache=false
2.创建实体类
public class Student { private Integer stu_id; private String stu_name; public Integer getStu_id() { return stu_id; } public void setStu_id(Integer stu_id) { this.stu_id = stu_id; } public String getStu_name() { return stu_name; } public void setStu_name(String stu_name) { this.stu_name = stu_name; } public Student(Integer stu_id, String stu_name) { this.stu_id = stu_id; this.stu_name = stu_name; } public Student(){ } }
3 创建Controller层
@RequestMapping("/getStudents") public String getStudents(Model model){ System.out.println("hello"); List<Student> studentList=new ArrayList<>(); Student student1=new Student(111,"张三"); Student student2=new Student(222,"李四"); Student student3=new Student(333,"王五"); studentList.add(student1); studentList.add(student2); studentList.add(student3); model.addAttribute("student",studentList); return "Hello"; }
4.编写html页面
<body> <table border="1"> <tr> <td>学生编号</td> <td>学生姓名</td> </tr> <tr th:each="stu:${student}"> <td th:text="${stu.stu_id}"></td> <td th:text="${stu.stu_name}"></td> </tr> </table> </body>
5.启动程序
@SpringBootApplication public class StartSpringBoot { public static void main(String[] args) { SpringApplication.run(StartSpringBoot.class,args); } }
6.运行 结果
SpringBoot使用thymeleaf案例的更多相关文章
- springboot整合 thymeleaf 案例
1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.GITHUB地址 https://github.com/nbfujx/springBo ...
- Springboot+JPA+Thymeleaf 校园博客完整小网站
本文所属[知识林]:http://www.zslin.com/web/article/detail/35 此项目是一个比较简易的校园博客.麻雀虽小五脏俱全,虽然是比较简易的但是涉及的知识点还是比较全面 ...
- 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础授权权限
上一篇<[原]无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限>介绍了实现Shiro的基础认证.本篇谈谈实现 ...
- 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限
开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他 ...
- 【Springboot】Springboot整合Thymeleaf模板引擎
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
- 从.Net到Java学习第九篇——SpringBoot下Thymeleaf
从.Net到Java学习系列目录 Thymeleaf概述 Thymeleaf 是一个流行的模板引擎,该模板引擎采用java语言开发.模板引擎是一个技术名称,是跨领域平台的概念,在java语言体系下有模 ...
- 从.Net到Java学习第六篇——SpringBoot+mongodb&Thymeleaf&模型验证
SpringBoot系列目录 SpringBoot整合mongodb MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.如果你没用过Mong ...
- SpringBoot 之Thymeleaf模板.
一.前言 Thymeleaf 的出现是为了取代 JSP,虽然 JSP 存在了很长时间,并在 Java Web 开发中无处不在,但是它也存在一些缺陷: 1.JSP 最明显的问题在于它看起来像HTML或X ...
- IDEA上创建 Maven SpringBoot+mybatisplus+thymeleaf 项目
概述 在WEB领域,Java也是在不断的探索和改进,从开始的JSP--->Struts1--->Struts2+Spring--->Spring MVC--->SpringBo ...
随机推荐
- yum命令安装jdk
1.查看是否已安装JDK,卸载 yum list installed |grep java java--openjdk.x86_64 :.b13.el7_5 @updates java--openjd ...
- java之hibernate之组合主键映射
1.在应用中经常会有主键是由2个或多个字段组合而成的.比如成绩表: 第一种方式:把主键写为单独的类 2.类的设计:studentId,subjectId ,这两个主键是一个组件.所以可以采用组件映射的 ...
- .net 使用SqlBulkCopy批量插入数据库
//一次批量插入100W条数据到数据库 static void Main(string[] args) { System.Random a = new Random(System.DateTime.N ...
- Oracle数据库之四大语言
一.数据定义语言: 1.用于改变数据库结构,包括创建.更改和删除数据库对象: 2.命令: create table :创建 alter table 修改 drop table 删除表 truncate ...
- Appscan漏洞之已解密的登录请求
本次针对 Appscan漏洞 已解密的登录请求 进行总结,如下: 1.1.攻击原理 未加密的敏感信息(如登录凭证,用户名.密码.电子邮件地址.社会安全号等)发送到服务器时,任何以明文传给服务器的信息都 ...
- 木马防杀 花指令 OllyDbg
打开木马 入口地址 添加花指令 全0的地方,可以插入花指令 保存为可执行文件 随便选择几行,右击 保存文件
- nrm 工具的使用
一.什么是nrm? 这是官方的原话: 开发的npm registry 管理工具 nrm, 能够查看和切换当前使用的registry, 最近NPM经常 down 掉, 这个还是很有用的哈哈 顾名思义,就 ...
- PHP使用Redis的Pub/Sub(发布订阅)命令
1.概念 名称 含义 channel 频道:生产者和消费者直接操作的对象 publish 生产者:向channel发送消息 subscribe 消费者:订阅一个或多个channel psubscrib ...
- selenium安装并导入pycharm
selenium安装 1.python的pip安装,命令pip install selenium 2.检查是否成功安装 打开pycharm-->File-->Settings-->P ...
- Keystore Problem: Cannot convert COMBINED of type class java.lang.String to class org.jivesoftware.openfire.spi.ConnectionType
go to: Server Manager -> System Properties Search for "xmpp.socket.ssl.client.keypass" ...