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. 20155315 2016-2017-2 《Java程序设计》第二周学习总结

    教材学习内容总结 在教材中,有一句话叫做 伪代码是最好的注释. 一开始我不理解什么是伪代码,但在参考了百度和C语言的学习过程后,我发现伪代码的作用就相当于是解决问题前期的流程图设计,伪代码设计好了之后 ...

  2. Storyboarding by Scripting

    Storyboarding by Scripting In the .osu file, under [Events]:Note: underscores can be replaced with s ...

  3. win10 64位redis的安装和测试

    步骤记录: 1.官网没有redis64位的版本,在git开源项目上找到64位的可用版本 https://www.cnblogs.com/tommy-huang/p/6093813.html 这里有下载 ...

  4. [BZOJ1565][NOI2009]植物大战僵尸-[网络流-最小割+最大点权闭合子图+拓扑排序]

    Description 传送门 Solution em本题知识点是用网络流求最大点权闭合子图. 闭合图定义:图中任何一个点u,若有边u->v,则v必定也在图中. 建图:运用最小割思想,将S向点权 ...

  5. RHSCA模拟考试

    开始考试:桌面是个黑框子 点击reboot按钮,破解密码 开机成功,输入startx进入图形界面 不能复制,要在物理机用ssh root@172.25.0.11 远程连接,就可以复制粘贴了 * Hos ...

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

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

  7. PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理

    只要有人用了: select t.* from 表名  t where 字段=xxx  for update 而不是: select t.rowid,t.* from 表名  t where 字段=x ...

  8. jenkins+jacoco+ant自动化代码和应用服务代码分离场景获取远程服务的覆盖率

    前提 自动化代码和应用服务代码分离.jenkins和tomcat服务器分离 思想 1.在tomcat启动javaagent监听. 2.运用其他job_B已部署的应用服务代码 3.拉取自动化代码,开始测 ...

  9. MySQL数据库--连接

    MySQL数据库的概念: MySQL数据库,包括客户端和服务端.客户端就是操作数据库的终端(命令行.navicat),服务端就是安装有MySQL软件的主机(本机或者服务器),MySQL数据库的端口一般 ...

  10. flexbox的应用

    2009年,display: box 就已经出现,但是直到IE11的发布,全部的主流浏览器才统一支持新的用法display: flex. 这里只说应用,浏览器的兼容处理会附在文章的末尾. 起步 在现代 ...