1. spring-boot-autoconfigure-1.5.1.RELEASE.jar!/org/springframework/boot/autoconfigure/web
上述jar的web包下,编写了自动配置Web项的逻辑
 
下面列举常用的几个类
ServerPropertiesAutoConfiguration和ServerProperties,自动配置内嵌Servlet容器
HttpEncodingAutoConfiguration和HttpEncodingProperties,自动配置http编码,默认utf-8
MultipartAutoConfiguration和MultipartProperties,自动配置文件上传
JacksonHttpMessageConvertersConfiguration,自动配置MappingJackson2HttpMessageConverterConfiguration与MappingJackson2XmlHttpMessageConverterConfiguration
WebMvcAutoConfiguration和WebMvcProperties,自动配置Spring MVC
 

Spring Boot推荐使用Thymeleaf作为模板引擎,其提供了完美的Spring MVC支持、

内嵌Tomcat、Jetty无法执行jar形式的jsp;Undertow不支持JSP

  • Thymeleaf页面基本样式
  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>首页</title>
  6. <link th:href="@{bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
  7. <link th:href="@{bootstrap/css/bootstrap-theme.min.css}" rel="stylesheet"/>
  8. <script th:src="@{jquery-1.10.2.min.js}" type="text/javascript"></script>
  9. <script th:src="@{bootstrap/js/bootstrap.min.js}"></script>
  10. </head>
  11. <body>
  12. Hello World
  13. </body>
  14. </html>
xmlns:th="http://www.thymeleaf.org" 引入Thymeleaf命名空间,将静态页面转化成动态页面。需要动态处理的元素将使用 th: 作为前缀
@{bootstrap/js/bootstrap.min.js} 引入Web静态资源
 
  • 访问model中元素属性
  1. <div class="panel panel-primary">
  2. <div class="panel-heading">
  3. <h3 class="panel-title">访问model</h3>
  4. </div>
  5. <div class="panel-body">
  6. <span th:text="${singlePerson.name}"></span>
  7. </div>
  8. </div>
访问model中singlePerson的name属性。这里需要为text属性添加th:前缀
 
  • 迭代元素
  1. <ul class="list-group">
  2. <li class="list-group-item" th:each="person:${people}">
  3. <span th:text="${person.name}"></span>
  4. <span th:text="${person.age}"></span>
  5. <button class="btn" th:onclick="'getName(\'' + ${person.name} + '\');'">获得名字</button>
  6. </li>
  7. </ul>
th:each做循环迭代person作为迭代元素,${person}访问model中元素
 
  • 空判断
  1. <div th:if="${not #lists.isEmpty(people)}">
  2. </div>
判断person是否为空,Thymeleaf支持>、<、>=、<=、==、!=、SpEL表达式
 
  • JavaScript中访问model中元素
  1. <script th:inline="javascript">
  2. var single = [[${singlePerson}]];
  3. console.log(single.name+"/"+single.age)
  4. function getName(name){
  5. console.log(name);
  6. }
  7. </script>
使用[[${modelName}]]获取model中的元素值
 
 
  • Thymeleaf与Spring MVC集成

pom

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  4. </dependency>
引入默认静态文件
静态文件包括 脚本、样式、图片,默认在src/main/resources/static下
 

编写Thymeleaf模板
默认位置在  templates
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>测试页面</title>
<link th:href="@{bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>
<link th:href="@{bootstrap/css/bootstrap-theme.min.css}" rel="stylesheet"/>
<script th:src="@{jquery-1.10.2.min.js}" type="text/javascript"></script>
<script th:src="@{bootstrap/js/bootstrap.min.js}"></script> </head>
<body>
Hello World<br/> <div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">访问model</h3>
</div>
<div class="panel-body">
<!--/*@thymesVar id="singlePerson" type=""*/-->
<span th:text="${singlePerson.name}"></span>
</div>
</div> <div th:if="${not #lists.isEmpty(people)}">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">列表</h3>
</div>
<div class="panel-body">
<ul class="list-group">
<li class="list-group-item" th:each="person:${people}">
<span th:text="${person.name}"></span>
<span th:text="${person.age}"></span>
<button class="btn" th:onclick="'getName(\'' + ${person.name} + '\');'">获得名字</button>
</li>
</ul>
</div>
</div>
</div> <script th:inline="javascript">
var single = [[${singlePerson}]];
console.log(single.name + "/" + single.age); function getName(name) {
console.log(name);
}
</script> </body>
</html>
 

Web模块:spring-boot-starter-web的更多相关文章

  1. Spring Boot 嵌入式Web容器

    目录 前言 1.起源 2.容器启动流程解析 2.1.获取应用类型 2.2.容器启动流程 3.加载 Web 容器工厂 4.总结 前言         最近在学习Spring Boot相关的课程,过程中以 ...

  2. 使用Spring Boot开发Web项目(二)之添加HTTPS支持

    上篇博客使用Spring Boot开发Web项目我们简单介绍了使用如何使用Spring Boot创建一个使用了Thymeleaf模板引擎的Web项目,当然这还远远不够.今天我们再来看看如何给我们的We ...

  3. Spring Boot:Web 综合开发

    Web 开发 Spring Boot Web 开发非常的简单,其中包括常用的 json 输出.filters.property.log 等 json 接口开发 在以前使用 Spring 开发项目,需要 ...

  4. 【spring boot】5.spring boot 创建web项目并使用jsp作前台页面

    贼烦的是,使用spring boot 创建web项目,然后我再idea下创建的,but 仅仅启动spring boot的启动类,就算整个项目都是好着的,就算是能够进入controller中,也不能成功 ...

  5. 通过docker-composer启动容器nginx,并完成spring.boot的web站点端口转发

    前面已经讲过2篇基于docker的mysql.redis容器编排并启动.这次将练习下nginx的docker方式的部署,以及通过nginx去代理宿主主机上的Web服务应该怎么配 PS:(这里由于ngi ...

  6. Spring Boot 2.X(四):Spring Boot 自定义 Web MVC 配置

    0.准备 Spring Boot 不仅提供了相当简单使用的自动配置功能,而且开放了非常自由灵活的配置类.Spring MVC 为我们提供了 WebMvcConfigurationSupport 类和一 ...

  7. Spring Boot开发Web应用之Thymeleaf篇

    前言 Web开发是我们平时开发中至关重要的,这里就来介绍一下Spring Boot对Web开发的支持. 正文 Spring Boot提供了spring-boot-starter-web为Web开发予以 ...

  8. Spring Boot Starter 介绍

    http://www.baeldung.com/spring-boot-starters 作者:baeldung 译者:http://oopsguy.com 1.概述 依赖管理是任何复杂项目的关键部分 ...

  9. spring -boot s-tarter 详解

    Starter POMs是可以包含到应用中的一个方便的依赖关系描述符集合.你可以获取所有Spring及相关技术的一站式服务,而不需要翻阅示例代码,拷贝粘贴大量的依赖描述符.例如,如果你想使用Sprin ...

  10. SpringBoot 之Spring Boot Starter依赖包及作用

    Spring Boot 之Spring Boot Starter依赖包及作用 spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. spri ...

随机推荐

  1. 20155322 2017-2018-1《信息安全系统设计》第十周 课下作业-IPC

    20155322 2017-2018-1<信息安全系统设计>课下作业-IPC 作业内容 研究Linux下IPC机制:原理,优缺点,每种机制至少给一个示例,提交研究博客的链接. 共享内存 管 ...

  2. ASCII, UNICODE, UTF-8, 字符集理解

    字符编码的发展历史 一个字节:最初一个字节的标准是混乱的,出现过4位.6位.7位的一字节标准,最终由于历史原因和物理存储需求(8位是2的3次方,方便物理存储),所以采用了8位为一个字节的标准. ASC ...

  3. 【LG4609】[FJOI2016]建筑师

    [LG4609][FJOI2016]建筑师 题面 洛谷 题解 (图片来源于网络) 我们将每个柱子和他右边的省略号看作一个集合 则图中共有\(a+b-2\)个集合 而原来的元素中有\(n-1\)个(除去 ...

  4. [css 实践篇]CSS中的尺寸单位

    绝对单位 px: Pixel 像素 pt: Points 磅 pc: Picas 派卡 in: Inches 英寸 mm: Millimeter 毫米 cm: Centimeter 厘米 q: Qua ...

  5. Maven学习(三)-----Maven本地资源库

    Maven本地资源库 Maven的本地资源库是用来存储所有项目的依赖关系(插件jar和其他文件,这些文件被Maven下载)到本地文件夹.很简单,当你建立一个Maven项目,所有相关文件将被存储在你的M ...

  6. 使用phpMyAdmin管理网站数据库(创建、导入、导出…)

    作为一名站长,最重视的就是网站的数据安全了.本节襄阳网站优化就来讲讲如何使用phpMyAdmin管理软件进行mysql数据库的管理,实现基本的数据库管理用户.数据库的创建.数据的导入和导出操作(网站备 ...

  7. Jenkins Tomcat安装设置

    Jenkins Tomcat安装设置 以下为必须满足Jenkins Tomcat设置的先决条件. 第1步:验证安装Java 要验证Java安装,打开控制台并执行以下Java命令. OS 任务 命令 W ...

  8. Consul 架构(译)

    Consul 架构 此篇文章主要对consul的相关内部技术细节进行简要概述. »术语 代理 - 代理是指consul集群中运行的consul实例,通过执行 consul agent 命令来启动. 代 ...

  9. Office 365 Powershell 连接命令

    国内版 第一步: Import-Module msonline Connect-MsolService 输入用户名密码 第二步: Get-MsolUser" 第三步: Set-Executi ...

  10. Sublime Text 2 - Unable to find git.exe 错误

    今日打开 Sublime Text 2,随即弹出 Package Control - Unable to find git.exe 错误.如下, 原因:曾经通过 git clone 命令获取过 Sub ...