1.搭建初始项目
springBoot配置文件:
1)pom.xml文件

<?xml version="1.0" encoding="UTF-8"?><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.st</groupId><artifactId>springBootDemo</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>springBootDemo</name><properties><!-- 输入编码 --><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!-- 输出编码 --><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><!--设置maven-compiler-plugin插件使用的jdk版本如果不指明版本,maven项目会用maven-compiler-plugin默认的jdk版本来进行编译,就容易出现版本不匹配的问题,导致编译不通过--><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><!-- jdk版本--><java.version>1.8</java.version></properties><!-- 包括了待继承的父工程所需要的信息 --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><dependencies><!--springboot启动类,核心类--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!-- 引入springMVC --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><!--<version>2.0.6.RELEASE</version>--></plugin></plugins></build>
</project>

2)resource中的application.yml文件:
注意:yml文件要严格缩进;每次缩进空两个空格;不能用Tab键缩进(会报错)

server:# 服务段口号port: 8080# 服务名称servlet:context-path: /bootDemo#-----加载静态资源存放路径:js、css、图片、多媒体等、html、jsp等resources:#static-locations: classpath: /static与下面static-path-pattern: /static/**这两个静态资源配置,只能同时用一个#配置前端页面访问目录及页面后缀名mvc:#静态资源映射路径static-path-pattern: /static/**view:prefix: classpath:/templates/suffix: .html

3)Application.java
Application是springBoot项目的启动类,启动类要在其他类的上一级目录
图示启动类为App

package com.st;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);//启动springBoot项目}
}

2.springBoot热部署、热依赖引入
项目修改后不需要再重新启动。热部署会自动更新(但是有时候不好使用QAQ)
1)pom.xml文件

 <!-- devtools 热部署 依赖包. --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope></dependency><build><plugins><plugin><configuration><!--fork:如果没有该项配置,devtools不会起作用,即应用不会restart--><fork>true</fork></configuration></plugin></plugins></build>
</project>

2)application.yml文件(每次缩进两空格,不能用tab缩进)

spring:#开启热部署(一直在改变,每次改变自动更新,不需要每次都重新启动)devtools:restart:enabled: true

3.thymeleaf标签引入
1)pom.xml配置文件

 <!-- 引入thymeleaf模板引擎 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>

4.thymeleaf标签使用
1)在html页面中引入thymeleaf命名空间

<!DOCTYPE html>
<!--在html页面中引入thymeleaf命名空间,即,此时在html模板文件中动态的属性使用th:命名空间修饰 。-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8">
</head>
<body>
</body>
</html>

2)输出:=后面的内容用" "括起来,用 ’ ’ 拼接字符串,用text输出

 <span th:text="'获取对象名:' + ${obj.name}"></span><!-获取对象名:张万森--><span th:text="'获取字符串' + ${x1}"></span><!-获取字符串:孟殷--><span th:text="'获取名字' + ${x2}"></span><!-获取名字:集美--><span th:text="'数字运算' + ${num + 1}"></span><!-数据运算:3-->

3)if-else

 <!--bool为true--><div th:if="${bool}"><span>yes</span></div><div th:unless="${bool}"><!--else--><span>no</span></div>

4)if

    <!--大   于  >  gt小   于  <  lt大于等于  >=  ge小于等于  <=  le等   于  ==  eq不 等 于 !=  ne--><div th:if="${num gt 2}"><span>num > 2 </span></div><div th:if="${num le 2}"><span>num le 2</span></div>
    <!--&& and|| or! not--><div th:if="${num le 2 && num ne 5}"><span>num le 2 && num ne 5</span></div>或:<div th:if="${num le 2} and ${num ne 5}"><span>num le 2 and num ne 5</span></div><span th:text="${not bool}"></span>

5)switch

 <!--num为2--><div th:switch="${num}"><span th:case="1">numb</span><span th:case="2">numb</span><span th:case="*">其他</span></div>

6)三元表达式

 <h2 th:text="${bool} ? 'bool is true' : 'bool is false'"></h2>

7)循环输出:

 <!--list是String类型集合--><table border="1"><tr th:each="str:${list}"><!--str遍历list中每个元素--><td th:text="${str}"></td><td th:text="${str.length()}"></td></tr></table>

iterStat称为状态变量,如果不声明状态变量,th会默认生成一个名为“变量名Stat”的状态变量,如上述循环输出中,默认状态变量名为:strStat。
状态变量iterStat的属性有:
index: 当前迭代对象的index(从0开始)
count: 当前迭代对象的index(从1开始)
size:遍历的对象的大小(元素个数)
current:当前迭代变量
even/odd:布尔值,当前循环是否是偶数/奇数(从零开始)
first:布尔值,当前循环是否是第一个
last:布尔值,当前循环是否是最后一个。

举例:

<table border="1"><tr th:each="str,iterStat:${list}"><td th:text="${iterStat.index}"></td><td th:text="${str}"></td><td th:text="${str.length()}"></td></tr></table>

html对应的controller方法:

 public ModelAndView page(){ModelAndView mv = new ModelAndView();User u = new User("张万森",18);mv.addObject("obj",u);mv.addObject("num",2);mv.addObject("bool",true);List<String> list = new ArrayList<>();list.add("林北星");list.add("嘎子");list.add("乔奈");mv.addObject("list",list);mv.addObject("x1","孟殷");mv.addObject("x2","集美");mv.setViewName("hello");return mv;}

controller类中:@RestController = @Controller + @ResponseBody
即@RestController 有@Controller 和 @ResponseBody的功能

springBoot配置、thymeleaf标签相关推荐

  1. SpringBoot整合Thymeleaf+EasyExcel实现excel文件的读取并展示,附加swagger2配置(超详细示范!)

    目录 1.Springboot整合Thyemleaf+EasyExcel 步骤 1.1 pom文件引入依赖 1.2 yml文件配置 1.3 config配置类 1.3.1 Swagger2配置类 1. ...

  2. spring boot构建基础版web项目(一)springboot、thymeleaf控制层基础构

    原文作者:弥诺R 原文地址:http://www.minuor.com/147852147/article 转载声明:转载请注明原文地址,注意版权维护,谢谢! 写前说明 根据个人在各篇博文中看到的信息 ...

  3. thymeleaf依赖_玩转SpringBoot集成 Thymeleaf 模版引擎

    随着互联网技术的发展,在前后端分离开发模式已经逐渐成为主流的今天,前后端技术的划分也越来越清晰,社会分工进一步细化,职业岗位也更加细分,慢慢开始就有了前端攻城狮和后端攻城狮,技术也进一步细分,出现了以 ...

  4. 九、SpringBoot集成Thymeleaf模板引擎

    Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:"赛母李府",大部分中国 ...

  5. springboot嵌入thymeleaf后css404_SpringBoot2整合Thymeleaf

    前言 什么是Thymeleaf Thymeleaf是适用于Web和独立环境的现代服务器端Java模板引擎. Thymeleaf的主要目标是为您的开发工作流程带来优雅的自然模板 -HTML可以在浏览器中 ...

  6. Springboot整合thymeleaf模板

    Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...

  7. SpringBoot+Mybatis+thymeleaf实现增删改查

    一.今天用SpringBoot整合thymeleaf做一套增删改查 1.导入依赖 <dependency><groupId>org.mybatis.spring.boot< ...

  8. springboot配置文件属性大全

    springboot配置文件属性大全 1. application.yml参数 1. application.yml参数 #-------------------------------------- ...

  9. springboot整合thymeleaf

    目录 一.介绍 二.Thymeleaf 的特点 三.语法规则 四.springboot中集成Thymeleaf 五.使用 六.将数据存入页面并取出 6.1 存入普通数据 6.1.2 存入对象 6.1. ...

最新文章

  1. 详解VS2012发布web api流程
  2. AI预测RNA结构登上Science封面,论文一作已成立药物公司开始招人
  3. 实用 —— PowerCLI (一)
  4. jsonp react 获取返回值_Django+React全栈开发:文章列表
  5. 5 仓库号xxx的主数据仍然现存不能删除(慎用)
  6. 【Virtual DOM】虚拟 DOM 和 Snabbdom 库
  7. Python列表常用操作,浅拷贝及深拷贝
  8. [转载] 【Python】range()、np.arange()、np.linspace()、np.logspace()的使用和区别
  9. zabbix监控 nginx 进程
  10. 当你在追梦的路上抱怨生活太累快要放弃的时候,不妨看看我的这篇文章
  11. OptiFDTD应用:纳米盘型谐振腔等离子体波导滤波器
  12. oceancolor数据批量下载
  13. 3个酷到没同学的冷门专业,开始逆袭了?
  14. java8-常用stream操作(1)
  15. 达人评测 华为手表 WATCH 3怎么样
  16. nginx events 模块配置
  17. 百位大整数的加法雏形——C语言
  18. 笔记本win10宽带共享wifi热点教程
  19. 海康机器人工业相机sdk简介
  20. rust自创服务器_用Rust写了一个简单的Web服务器

热门文章

  1. 又是一年读书日,这十本书你居然还没读过?
  2. 桌面计算机怎么覆盖文件,Win7电脑桌面图标被覆盖的解决技巧
  3. 兼顾美观和实用的标签页插件——iTab
  4. 495. Teemo Attacking
  5. 科技 |『2017CES』雷蛇发布三面屏笔记本
  6. Echarts饼图标题文字居中
  7. 小马哥---高仿苹果5s 主板型号A182 芯片为6582 拆机主板刷机多图展示
  8. springmvc下载文件以及下载大文件方法
  9. 最近总蓝屏死机,发现是其中一个svchost进程一直占用我cpu使用率25%导致机器非常热,散热风扇狂转,像被人当矿机了
  10. 16条你应该珍藏,没事就读读的精辟语录!