maven搭建springboot+thymeleaf

快速搭建Spring Boot+Spring MVC Spring Boot的出现大大简化了Spring项目的初始搭建和开发过程,今天我们快速搭建一个带有页面渲染(themeleaf模板引擎)的Spring Boot环境。 一、首先我们在IDEA中创建一个Maven项目 勾选create from archetype,选择webapp 二、在pom文件中添加Spring Boot依赖和themeleaf依赖       org.s 阅读详情

maven搭建springboot+thymeleaf

1.新建maven

自己创建包和文件夹。目录结构如下:

image-20200624082827011

image-20200624082932691

2.pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.ufo</groupId>
	<artifactId>test</artifactId>
	<version>0.0.1-SNAPSHOT</version>

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


	<build>
		<plugins>

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

</project>
3.启动类app.java:
package com.ufo.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class app {

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

}

4.testController.java

@Controller 
public class testController{
    
    @RequestMapping("/hello") 
    public String hello(HttpServletRequest request, @RequestParam(value = "name", defaultValue = "springboot-thymeleaf") String name) { 
        request.setAttribute("name", name); 
        return "hello"; 
    } 
}
5.配置文件application.yml:
spring.thymeleaf.prefix=classpath:/templates/ 
spring.thymeleaf.check-template-location=true 
spring.thymeleaf.suffix=.html 
spring.thymeleaf.encoding=UTF-8 
spring.thymeleaf.content-type=text/html 
spring.thymeleaf.mode=HTML5 
spring.thymeleaf.cache=false
6.测试界面hello.html
<!DOCTYPE html> 
<html lang="en" xmlns:th="http://www.thymeleaf.org"> 
<head> 
    <meta charset="UTF-8"/> 
    <title>springboot-thymeleaf测试</title> 
</head> 

<body> 
    <p th:text="'hello, ' + ${users} + '!'" /> 
</body>

</html>

启动启动类。成功。

7.thymeleaf列表
<!DOCTYPE html> 
<html lang="en" xmlns:th="http://www.thymeleaf.org"> 
<head> 
    <meta charset="UTF-8"/> 
    <title>springboot-thymeleaf测试</title> 
</head> 

<body> 
  <table border="1">
    <tr>
        <th>用户名</th>
        <th>邮箱</th>
        <th>状态变量:index</th>
        <th>状态变量:count</th>
        <th>状态变量:size</th>
        <th>状态变量:even</th>
        <th>状态变量:odd</th>
    </tr>
    <tr  th:each="user : ${users}" >
        <td th:text="${user.id}"></td>
        <td th:text="${user.name}"></td>
        <th th:text="${user.feature}"></th>
        <th th:text="${user.status}"></th>
        <th th:text="${user.dornum}"></th>
    
    </tr>
</table>
</body>

</html>
8.thymeleaf的ifelse
   <td th:switch = "${ user.status ==1  }" >
                <div th:case="true" th:text = "在校" ></div>
                <div th:case="false" th:text = "离校" ></div>
        </td>

或者用三目运算:

th:text="${emp.gender==0?'女':'男'}"
9.小心只返回hello,不返回界面

用controller不用RestController

10.只编译html
      spring.thymeleaf.cache=false
实验四 基于IDEA+SpringBoot+Maven+Thymeleaf的系统实现实验目的 通过这次实验,我学习了如何成功进行IDEA+SpringBoot+maven的系统实现,搭建好IDEA+SpringBoot+maven的系统环境,成功地安装并配置了maven的运行环境,学会了创建springboot的三种方式,并且能将之前的实验结合起来运用。pom.xml中引入thymeleaf依赖,在classpath:/templates/下新建HTML页面(可采用实验一创建的页面),新建controller进行测试,访问页面后返回success成功数据。同时掌握和thymeleaf的基本语法。 阅读详情

相关推荐

简单搭建 springboot+maven+MySQL+mybatisPlus+thymeleaf+(log4j+logback) 项目

一、使用springBoot 官网提供的工具初始化springBoot 项目 1. 访问网站:https://start.spring.io/ 看到如下页面, 选择使用maven 管理项目,使用Java语言,使用最新版本 2. 导入依赖包(这里我们先导入一个最基础的就好,后续根据功能再一个一个导入) 3. 项目打包导出 点击导出zip,解压到自己的文件夹下,idea 引入,项目结构如下 4. 该项目已经可以跑rest 风格的请求了,做个小测试体验以下 我们在:com.bl.blSpboot 下建个

qq_35972082的博客 2046

Maven + SpringBoot + Thymleaf 项目搭建(IDEA)

Maven + SpringBoot + Thymleaf 项目搭建 一、创建一个Maven项目 打开IDEA,File——>New——>Project…,在对话框左侧选择Maven,点击Next。 在GroupId输入包名,在ArtifactId输入项目名,点击Next。 输入项目名和选择项目位置。点击Finish,项目创建完成。 项目的初始目录结构如下: 二、配置pom.x...

qq_40373914的博客 1028

点餐系统数据库设计--SQL Server

友情链接 1、学生成绩管理系统数据库设计–MySQL 学生成绩管理系统数据库设计–MySQL 2、医疗信息管理系统数据库–MySQL 医疗信息管理系统数据库–MySQL 3、邮件管理数据库设计–MySQL 邮件管理数据库设计–MySQL 4、SQL Server医疗信息管理系统数据库【英文版-源码】–(Medical Management System Database) SQL Server医疗信息管理系统数据库【英文版-源码】–(Medical Management System Database) 5

若如初见 8万+

maven springboot thymeleaf环境搭建

一、添加pom.xml依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 二、在application.pr...

tiger-guo 398

一种基于频域滤波法消除干扰项与角谱法重构技术的数字全息显微台阶形貌测量实例分析

一种基于频域滤波法消除干扰项与角谱法重构技术的数字全息显微台阶形貌测量实例分析

简单光学 2035

nnDetection复现Luna16 附模型

淘论文发现nnDetection框架对肺结节的检测效果挺好,便跑了跑复现了下, 作者诚不欺人,确实挺好, 并附上我依据文档训练的模型。

HeavenWalker 2597

SpringBoot + thymeleaf基本运用

1、maven配置(给maven的settings.xml配置文件的Profiles标签添加如下内容) <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> <value>dev&

abcd 193

【飞控】MATLAB中UAV Toolbox Support Package for PX4 Autopilots和Pixhawk Pilot Support Package (PSP) 的关系?

区分UAV Toolbox Support Package for PX4 Autopilots和Pixhawk Pilot Support Package (PSP)

m0_58373406的博客 739

【Spring Boot】Spring Boot + Thymeleaf + Maven 使用示例

文章目录示例工具版本在 Spring Boot 中集成 Thymeleaf 3使用 Thymeleaf使用 Thymeleaf 创建 < form >国际化(i18n)验证 | Validation日志 | Logging完整示例1. 在 Eclipse 中项目结构 本页将介绍Spring Boot + Thymeleaf + Maven的例子。 我们将提供如何使用Spring Boot的Thymeleaf来实现国际化(i18n)、表单验证和日志记录。 如果Spring Boot在类路径中扫描到

猫巳的博客 2463

基于YOLOv10的机器人抓取引导系统:从物体检测到精准抓取

python# 数据标注工具简化版import os"""启动标注工具""""""标注单张图像"""print(f"标注图像: {os.path.basename(img_path)}")print("请在图像上绘制抓取矩形框...")# 这里应该实现交互式标注界面# 简化版本直接返回示例标注# 示例标注数据"""保存标注结果"""# 保存为YOLO格式# 转换为YOLO格式。

YOLO 378

1、vectorCast单元测试常用操作

进入软件主页面,点击file,选择set working directory,随便选择一个保存该项目的目录即可。

weixin_59334478的博客 2157

SpringBoot ( 六 ) thymeleaf

3.thymeleaf thymeleaf : 伴随 SpringBoot 流行开始流行的页面标签 3.0.准备 3.0.1.Maven导入依赖 在pom.xml 文件中增加thymeleaf的依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf&l

yuanchun的知识整理 2940

推荐系统中召回率Recall计算方式附代码

Recall(召回率)是指在所有实际有交互的用户 - 物品对中,推荐系统成功预测出的比例。具体来说,设所有有交互的用户 - 物品对为S,推荐系统预测出的用户 - 物品对为T,则Recall的计算公式为:

优快云 精品推荐 1842

一文读懂!IDEA+SpringBoot+Maven+Thymeleaf 系统搭建与实践

在 Java 开发领域,IDEA、Spring Boot、Maven 和 Thymeleaf 都是非常重要的技术工具。IDEA 是强大的集成开发环境,Spring Boot 极大简化了 Spring 应用开发,Maven 用于项目构建和依赖管理,Thymeleaf 则是优秀的模板引擎。本文将详细介绍如何基于这些技术搭建一个完整的系统,并分享实际开发中的经验和技巧。

u014114223的博客 1239

(4-2)A*

实际已经花费的代价(g(n)):从起点到当前节点n的实际路径代价。启发式估计的剩余代价(h(n)):从当前节点n到目标节点的估计路径代价。这是A算法的关键之一,启发式函数要足够接近实际代价,但又要高效计算。如果启发式函数等于0,A算法就相当于Dijkstra算法。实现A*算法的核心步骤如下所示。(1)初始化:将起点加入开放列表(open list),并将其f值设为g值和h值的和。(2)循环:从开放列表中选择具有最小f值的节点作为当前节点。如果当前节点是目标节点,算法结束;

码农三叔 1807

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Springboot+maven+mysql+thymeleaf 简单框架搭建

1.下载maven,安装maven,创建maven项目 http://blog.youkuaiyun.com/lanqibaoer/article/details/51898635?locationNum=1&fps=1 2.maven项目的pom.xml引入jar包,如下 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="htt

lanqibaoer的专栏 2815

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Springboot+mybaties+pagehelper+thymeleaf+layui+maven搭建项目

一、创建maven项目,项目结构如图 关于项目的创建这里就不在多做介绍,如有不懂的,可以留言 二、在pom文件中引入所需要的jar 如下是我pom文件引入的jar及详细说明: &lt;!-- mysql集成 start --&gt; &lt;dependency&gt; &lt;groupId&gt;mysql&lt;/gr...

qq_28245087的博客 2565

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

JAVA_idea上创建springboot项目

目录springBoot jdk http://start.spring.io https://start.aliyun.com项目名 包名 jdk 打包类型基本jar包 现在可以加上 ,在使用时先把多余jar包注释 进行测试 避免因jar包影响测试包结构 Controller是我后期加上测试的 .mvn mvnw mvnw.cmd可以删除掉启动类pom.xml 文件 基本的项目Maven加载完成Controller 开始测试 基本跳转页面运行 进行简单配置下正常启动页面查看 localhos

zzh18334820165的博客 256

使用Maven搭建一个多模块项目,基于SpringBoot整合SpringMVC + Mybatis + Thymeleaf,完成一个简单的单表操作项目

springboot多模块项目

2201_75927593的博客 413

SpringBoot1.5.7模板引擎thymeleaf报错问题

刚开始搭建项目,报错总是莫名奇怪: 图一 图二  图三    究其原因是jar包的问题,本人用的maven3.6版本,换成图三的配置就OK了: &lt;properties&gt; &lt;java.version&gt;1.8&lt;/java.version&gt; &lt;thymeleaf.version&gt;3.0.11.RELEASE...

易大师不易 637

springboot+mybatis+bootstrap+thymeleaf前后端框架搭建

大家对thymeleaf框架比较不熟悉,其实thymeleaf是spring官方推荐的前台框架,今天就教大家如何使用thymeleaf整合到springboot中。 创建maven项目,pom.xml文件添加springboot需要的依赖包 <dependencies> <!--springboot启动依赖包--> <dependency> <groupId>org.springframework.boot</group

qq_43248715的博客 1260

springBoot+mybatis+thymeleaf+oracle+maven搭建web项目

我用的开发是IDEA,所以首先建立spring-boot项目,这个在spring-boot中很简单 这是完成搭建后的目录结构,后面如果我说的文件不知道放在哪,可以返回看看 1.引入thymeleaf:在maven中pom.xml 中加入依赖 &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/group...

gaojiajie333的博客 929

springboot mybatis thymeleaf maven mybatis-generator搭建系统框架

1.版本:springboot 使用idea工具搭建springboot项目 首先maven要自己配置一下国内的镜像地址,不然会导致项目构建失败 pom.xml文件配置 mybatis-generator 根据数据库表结构自动创建bean、dao、xml 1、在pom.xml文件中引入相应jar包 2、创建generatorConfig.properties和generatorConfig....

卖奶茶的程序员的博客 226

整合SpringBoot+MybatisPlus+thymeleaf项目创建

总结:第一次使用 SpringBoot 还是很生疏,就当污染污染大家的眼睛吧,写的也不够清晰,希望有大佬能指出问题,后续争取将这个项目进行完善,下一步打算增加一个登录注册的相关功能。1.2勾选Web、mysql、Lombox、Thymeleaf (由于我本人不会VUE是能使用html了)2、修改application.yml的,添加port为请求的端口号。resources--->thymeleaf文件夹创建一个Test.html的页面。6、配置thymeleaf,application.yml添加。

weixin_42232868的博客 2197

springboot 2.3_实战演练【SpringBoot入门搭建】

点击蓝色“IT乾坤”关注我哟加个“星标”,一起成长项目搭建使用技术开发环境:idea框架:Springboot工具:Maven前端:Html,Thymeleaf后台:Mybatis数据库:Mysql项目搭建【01】点击idea的File->new->Project,点击nextspringboot-build【02】选择Spring Initializr,点击nextspri...

weixin_39986543的博客 127

springboot+maven+thymeleaf demo

此为转载,非原创 本案例使用thymeleaf,与springboot配置使用。thymeleaf是一种模板语言,可以动态或者静态显示文本内容。   1 、项目结构           2、构建springboot项目     通过idea的new project构建springboot项目,如果mvn比较慢,建议更改maven目录下的conf中的setting.xml,找到mirro...

weixin_44678034的博客 478
上一篇: notepad++变卡
下一篇: Ubuntu 16.04卸载一些不必要的预装软件
UFOO2
博客等级 码龄6年 7粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值