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. 实验2 Windows口令破解

    实验2 Windows口令破解 实验目的 了解Windows口令破解原理 对信息安全有直观感性认识 能够运用工具实现口令破解 实验工具 LC5 实验原理 口令破解方法: 口令破解主要有两种方法:字典破 ...

  2. 20155323 2016-2017-2《Java程序设计》课程总结

    20155323 2016-2017-2<Java程序设计>课程总结 课程与实验链接 预备作业一:新学期,新展望 预备作业二:游戏经验 预备作业三:安装虚拟机和Linux系统的学习 201 ...

  3. day5 二值化

    1.otsu二值化 # coding=utf-8 import cv2 import numpy as np from matplotlib import pyplot as plt #1.读入图像 ...

  4. Luogu3804 【模板】后缀自动机

    题面 题解 一个串的出现次数等于$endpos$的大小,也是$parent$树上节点的$size$大小, 构建出后缀自动机,按拓补序,模拟即可. 代码 #include<cstdio> # ...

  5. 字典(dict)的反转

    1.今天在写12306查询余票时,想给定字典(dict)的值,从而得到字典(dict)的键,但好像字典(dict)方法中没有与此相关的方法,只能退而求其次,反转字典(dict),将原字典(dict)的 ...

  6. Linux查看文件内容

    查看文件内容的命令: cat:连接文件并且打印在标准输出 tac:连接并且倒序打印文件 more:屏幕文件熟读过滤器 less head:输出文件的第一部分 tail:输出文件最后的部分 nl:输出文 ...

  7. selenium +java 多个类公用driver问题

    问题点:太久没有写selenium代码,居然把driver公用的问题忘记了,即:每写一个测试类,执行过程中都会新建一个窗口,这样应该说是非常不专业的. 大概想了一个方法,虽然看起来也不怎么专业,但感觉 ...

  8. PHP精确到毫秒秒杀倒计时实例

    精确到毫秒秒杀倒计时PHP源码实例,前台js活动展示倒计时,后台计算倒计时时间.每0.1秒定时刷新活动倒计时时间. PHP: // 注意:php的时间是以秒算.js的时间以毫秒算 // 设置时区 da ...

  9. 算法工程师进化-NLP之主题模型

    1 引言 主题模型是文本挖掘的重要工具,近年来在学术界和工业届都获得了非常多的关注.学术界的工作主要集中在建模层面,即提出各种各样的主题模型来适应不同的场景,因此缺乏指导主题模型在工业场景落地的资源和 ...

  10. python编辑购物车

    一.需求分析 输入工资金额,进入购物车,并打印输出商品编号和价格,用户可以通过输入商品编号进行商品选购 余额不足时,打印提示信息 通过q进行退出结算 购物车能够循环购物 二.代码实现 ShoopCar ...