spring boot框架与thymeleaf模板引擎的整合

Spring Boot 本文介绍了SpringBoot框架的核心概念、功能特性及开发实践。主要内容包括: SpringBoot基础 简化了Spring的繁琐配置 采用约定大于配置思想 提供自动配置和起步依赖功能 支持多种项目构建方式 核心功能 简化Web开发,支持Servlet/Filter/Listener注册 提供Thymeleaf模板引擎 整合MyBatis等持久层框架 支持热部署、定时任务等 高级特性 内容协商机制 国际化支持 参数校验 指标监控(Actuator) 日志管理(Logback) 项目部署 多环境配置 Doc 阅读详情

1.首先新建项目
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

项目这就创建好了,下面配置pom.xml文件

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- ThymeLeaf 依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

2.实现功能
在这里插入图片描述
student实体类;

public class Student {
private int id;
private String name;
private String num;
private int sex;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getNum() {
    return num;
}

public void setNum(String num) {
    this.num = num;
}

public int getSex() {
    return sex;
}

public void setSex(int sex) {
    this.sex = sex;
}

public Student(int id, String name, String num, int sex) {
    this.id = id;
    this.name = name;
    this.num = num;
    this.sex = sex;
}


@Override
public String toString() {
    return "Student{" +
            "id=" + id +
            ", name='" + name + '\'' +
            ", num='" + num + '\'' +
            ", sex=" + sex +
            '}';
}

studentController类:

package com.example.demo.student.controller;
import com.example.demo.student.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("stu")
public class StudentController {

@RequestMapping
public String list(Model model)
{
    List<Student>  list = new ArrayList<>();


    list.add(new Student(1,"张三","20141",1));
    list.add(new Student(2,"李四","20142",0));
    list.add(new Student(3,"王五","20143",0));
    list.add(new Student(4,"还是","20144",1));
    model.addAttribute("studentList",list);
    return "stu";
}

启动文件:

package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
}

html页面:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

<head lang="en">
<meta charset="UTF-8" />
<title></title>
</head>
<body>


<table border="1">

<tr>
    <td>ID</td>
    <td>名字</td>
    <td>学号</td>
    <td>性别</td>
</tr>
<tr th:each="student:${studentList}">
    <td th:text="${student.id}"></td>
    <td th:text="${student.name}"></td>
    <td th:text="${student.num}"></td>
    <td th:text="${student.sex}==0?'女':'男'"></td>
</tr>
</table>
</body>
</html>

启动好了:(Springboot中自带tomcat,端口默认8080)
在这里插入图片描述
html页面显示:
在这里插入图片描述

Spring Boot基础学习笔记09:Thymeleaf模板引擎 1. 了解Spring Boot支持的视图技术; 2. 掌握Thymeleaf常用标签; 3. 掌握Thymeleaf标准表达式; 4. 掌握Thymeleaf基本使用; 5. 掌握使用Thymeleaf完成数据的页面展示 阅读详情

相关推荐

SpringBoot整合Thymeleaf的实践教程与示例

在现代的Web开发中,模板引擎扮演着将数据与视图分离、美化页面输出的重要角色。SpringBoot作为一款旨在简化Spring应用的初始搭建以及开发过程的框架,与Thymeleaf的整合实现了快速、简便的模板渲染。Thymeleaf不仅支持服务器端渲染,还能够在浏览器中直接运行,增强了前后端的交互体验。虽然Thymeleaf提供了丰富的内置标签,但在一些特定场景下,内置标签无法满足需求时,可以自定义逻辑进行处理。创建一个Dialect是扩展Thymeleaf功能的有效途径。

weixin_42453228的博客 1260

Spring Boot开发之Mybatis-Plus、SpringSercurity

MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。

不服输的小乌龟 2043

从零开始:如何在Windows上搭建Airsim仿真环境(避坑指南)

本文是一份详细的Windows平台AirSim仿真环境搭建指南。文章从硬件要求、Visual Studio与虚幻引擎安装开始,逐步讲解AirSim插件编译、UE项目配置,并重点介绍了通过WSL2连接PX4飞控软件实现软件在环仿真的完整流程。内容涵盖常见问题排查与性能优化,旨在帮助开发者避开常见陷阱,高效构建可用于无人机算法开发的虚拟测试平台。

earth的博客 301

springboot中使用thymeleaf

导读 thymeleaf简介 springboot中使用thymeleaf thymeleaf参考资料 注:这里示例主要展示在springboot框架下,thymeleaf的简单应用,故不做深入讨论。        最近在学习springboot框架,使用到了thymeleaf模板引擎,在此记录。一是分享一些小经验,二是如果自己忘了方便查阅。   一、thymeleaf简介  ...

Evan's Blog ٩(๑❛ᴗ❛๑)۶ 9237

opencv的cmake报错

1、下载 ippicv_2021.8_win_intel64_20230330_general.zip、v0.1.2a.zip、opencv_videoio_ffmpeg.dll、opencv_videoio_ffmpeg_64.dll、ffmpeg_version.cmake。由于下载源在https://raw.githubusercontent.com,由于网络原因下载不顺畅,可以先找到文件下载到对应文件夹下,或者更改网络环境。ffmpeg_version.cmake文件,打开后显示如下, 另存即可。

nownow_的博客 1299

实战复盘:一次绕过WAF的EDUSRC SQL注入漏洞挖掘

本文详细复盘了一次针对教育行业网站的SQL注入漏洞挖掘实战。通过手动信息收集发现可疑点,并利用‘+’号替换空格等技巧,成功绕过WAF(Web应用防火墙)的拦截。文章逐步演示了从判断注入点到手工获取数据结构、最终解密进入后台的完整过程,并总结了手工测试的优势及高级绕过思路,强调了在EDUSRC等授权范围内进行安全测试的重要性。

weixin_28622215的博客 191

ThymeleafUtil - 文件生成 Utils-ThymeleafUtil - 工具类

ThymeleafUtil - 工具类 maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId&g...

scdncby的博客 2238

自动驾驶仿真:python和carsim联合仿真案例

carsim内部有许多相关联合仿真的demo,simulink、labview等等都有涉及,这里简单介绍下python和carsim联合仿真的方法,虽然carsim官方有个Steer_Control.py相关的案例,但是感觉比较冗余,这里抽出重点部分和大家交流探讨下。提示:以下是本篇文章正文内容,下面案例可供参考1、这里关于solvers的细节其实都没说,因为里面确实也没什么内容好讲的,本质就是调用carsim.dll,如果你需要更多的函数解析其实可以看vs_api.h,路径在,具体内容如下图所示。

zataji的博客 9062

Spring Boot 的视图(Thymeleaf)

视图技术

daqi1983的博客 8080

Qt实现思维导图功能5『纵向分布模式』

思维导图纵向分布模式:模式一

浮生流年的博客 1057

slew dreate,slew threshold与transition计算

​只看rise情况下,from pin取slew threshold10%-90%的区间,slew derate为1,计算得到transition为1.002e-10,to pin的slew threshold 为30%-70%,slew derate 0.5,从波形列表上取相近的值3.75e-10和8.75e-10,计算得到transition为(8.75e-10-3.75e-10)/0.5=1e-9,考虑精度和取值区间问题,基本符合工具计算的值,如下:​。如下示例,在.lib库中有定义以下内容。

m0_61544122的博客 793

Thymeleaf简单入门使用

创建一个web项目,引入jar包 <properties> <org.thymeleaf.version>3.0.11.RELEASE</org.thymeleaf.version> <junit.verison>4.12</junit.verison> </properties> <dependencies> <!-- 配置thymeleaf依赖 --> <depe

Shuttengr的博客 651

BiSeNet:面向实时语义分割的双边网络

BiSeNet 系列重新定义了实时语义分割的范式“不要在速度和精度之间妥协——用架构创新,两者兼得。V1:提出双边解耦思想,启发后续大量工作;V2:通过极致轻量化,证明小模型也能高精度;V3(工业版):推动端侧 AI 落地,成为行业标准之一。如今,BiSeNet 已成为嵌入式视觉系统的默认选择,其设计理念(解耦、轻量、融合)被广泛应用于目标检测、姿态估计等领域。

浩瀚之水的专栏 268

04 Spring Boot整合 Thymeleaf模板引擎

Thymeleaf 是一个优秀的、面向Java 的XML庆HTML/HTML5 页面模板,具有丰富的标签语言和函数。因此,在使用Spring Boot 框架进行页面设计时, 一般都会选择Thymeleaf 模板。 关于Thymeleaf,可到官方网站学习:https://www.thymeleaf.org/documentation.html 常用的表达式、标签和函数如下: 常用表达式: ${}...

数据知道的博客 2万+

【爬虫实战】Instagram博主图片爬取:模拟登录+滚动加载,轻松抓取高清美图

在当今社交媒体时代,Instagram作为全球最受欢迎的图片分享平台之一,汇聚了无数优质博主的海量精美图片。对于数据爱好者、营销分析师、AI训练数据收集者来说,如何高效、稳定地爬取Instagram博主的图片,成为了一项极具实用价值的技术挑战。然而,Instagram的反爬机制日益严格,传统的静态页面请求已经无法满足需求。本文将带你从零开始,使用2024-2025年最新技术栈,实现模拟登录、滚动加载、高清图片下载的全流程爬虫。✅ 全流程代码可直接运行✅ 模拟手机端请求绕过反爬。

2201_76125261的博客 596

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

整合thymeleaf模板引擎

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33811961的博客 108

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Thymeleaf模板引擎从入门到实战:Spring Boot整合与核心用法详解

本文全面介绍Thymeleaf模板引擎的核心功能与Spring Boot整合实践,涵盖数据绑定、条件循环、表单处理等关键特性。通过代码示例演示从基础语法到文件模板的进阶使用,详解Spring Boot自动配置原理及常用配置项,并给出Controller与模板交互的完整开发流程,帮助开发者快速掌握现代化Java Web页面渲染技术。

m0_73941339的博客 2698

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

springboot2.x整合shiro +themleaf

1.项目结构: 2.先整合themleaf 结构: 步骤: 1.在pom.xml中加入依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 如果创建

辰星 350

IDEA2023 SpringBoot整合Thymeleaf(四)

IDEA2023 SpringBoot整合Thymeleaf(四)

分享我的点点滴滴,在成长路上与你同行! 1489

spring-boot2.0 thymeleaf bootstrap 整合示例

spring-boot2.0 thymeleaf bootstrap 整合示例 本文主要讲述如何结合在springboot项目中结合thymeleaf和bootstrap。最后会把项目的下载地址放出来。 先看看最终效果: 效果看完之后,有木有心动,接下来我们一起自己动手打造一个。 新建项目 首先在idea或者eclipse(STS)中新建springboot项目,在选择依赖(De...

xqlsrjjjh 1万+

Spring-boot的简单实例

Spring-boot 一. 第一个Spring-boot的应用 1.1 maven配置 ​ 在maven文件中加入如下的依赖: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId...

youhaiguo的博客 6374

手工配置springboot + spring security + thymeleaf + thymeleaf-extras-springsecurity

thymeleaf-extras-springsecurity是thymeleaf模板框架与spring security框架的扩展包,主要实现在thymeleaf的模板页面中可以很方便的调用security框架返回的用户验证和权限信息。因为spring boot并没有对该扩展实...

493

themleft模板库_Thymeleaf模板引擎常用总结

一:语法简单总结Thymeleaf是一个Java类库,是xml/html/html5的模板引擎,SpringBoot框架推荐在MVC的Web应用做做View层使用.SpringBoot中整合Thymeleaf依赖如下.org.springframework.bootspring-boot-starter-thymeleaf3.0.9.RELEASE2.1.1UTF-8UTF-81.8Thymele...

weixin_33419842的博客 483

springboot resources路径_Spring Boot 系列:(4)Thymeleaf篇

写在前面 这是一个针对Spring Boot的学习系列,我把每一篇文章的知识点都写成了一个个独立的小项目,源码已经上传github。大家可以对照源码看文章,加深理解。地址如下: https://github.com/zhangzezhai/SpringBootDemo.git如果能帮助大家,请反手给个✨ star 哦 ~!也可以去公众号阅读更多内容:Java开发训练营前言 今天我们来简单说一下,S...

weixin_39914752的博客 355

【超详细】SpringBoot与Shiro整合-权限管理实战实操(附源码地址)

一、搭建SpringBoot开发环境 1. 安装好开发软件和Maven等 开发工具:Spring Tool Suite(TST) Maven :3.3.9。 jdk:1.8 2. 创建springboot项目(此功能需要联网) 3. pom.xml文件配置 <?xml version="1.0" encoding="UTF-8"?> <projec...

丶自定义 9418
上一篇: linux系统(乌班图为例)和windows系统的文件与目录的区别
下一篇: Linux常用终端命令简单版
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值