一、简介

1.1 引入SpringBoot模块

  在介绍Web开发模块之前,先总结一下SpringBoot中如何引入某一个模块,我们知道,SpringBoot将功能模块封装为一个个的Starter

  • 1)、创建SpringBoot应用,选中我们需要的模块;
  • 2)、SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置就可以运行起来
  • 3)、自己编写业务代码;

  • 这个场景SpringBoot帮我们配置了什么?能不能修改?能修改哪些配置?能不能扩展?

  1. xxxxAutoConfiguration:帮我们给容器中自动配置组件;
  2. xxxxProperties:配置类来封装配置文件的内容;

1.2 SpringBoot对静态资源的映射规则

  • 1)、所有 /webjars/** ,都去资源jar包下 classpath:/META-INF/resources/webjars/ 找资源;

    • webjars:以jar包的方式引入静态资源;

webjars网站,进入网站,如下:

<!‐‐引入jquery‐webjar 在访问的时候只需要写webjars下面资源的名称即可 ‐‐>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>

示例
如果引用jquery,那么路径应该写为:

localhost:8080/webjars/jquery/3.4.1/jquery.js
  • 2)、"/**" 访问当前项目的任何资源,都去(静态资源的文件夹)找映射
"classpath:/META‐INF/resources/",
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/"
"/":当前项目的根路径

示例

localhost:8080/abc # 去静态资源文件夹里面找abc
  • 3)、欢迎页; 静态资源文件夹下的所有index.html页面;被"/**"映射;

示例: localhost:8080/ 找index页面

  • 4)、所有的 **/favicon.ico 都是在静态资源文件下找;

二、模版引擎

2.1 简介

  • 我们常见的模版引擎有:JSP、Velocity、Freemarker、Thymeleaf
  • SpringBoot官网推荐我们用Thymeleaf

原理图如下:

2.2 引入thymeleaf


<properties>
<!-- 修改版本 -->
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
<!-- 布局功能的支持程序 thymeleaf3主程序 layout2以上版本 -->
<!-- thymeleaf2 layout1 -->
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
</properties> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2.3 Thymeleaf使用

ThymeleafProperties 类中我们可以看出Thymeleaf 如何使用以及配置信息:

@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties { private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8; public static final String DEFAULT_PREFIX = "classpath:/templates/"; public static final String DEFAULT_SUFFIX = ".html";
// ....省略...
}
  • 只要我们把HTML页面放在classpath:/templates/,thymeleaf就能自动渲染;

  • 1、导入thymeleaf的名称空间

<htmllang="en"xmlns:th="http://www.thymeleaf.org">
  • 2、使用thymeleaf语法;

【后续整理】

【SpringBoot】Web开发的更多相关文章

  1. SpringBoot Web开发(5) 开发页面国际化+登录拦截

    SpringBoot Web开发(5) 开发页面国际化+登录拦截 一.页面国际化 页面国际化目的:根据浏览器语言设置的信息对页面信息进行切换,或者用户点击链接自行对页面语言信息进行切换. **效果演示 ...

  2. SpringBoot Web开发(4) Thymeleaf模板与freemaker

    SpringBoot Web开发(4) Thymeleaf模板与freemaker 一.模板引擎 常用得模板引擎有JSP.Velocity.Freemarker.Thymeleaf SpringBoo ...

  3. 【SpringBoot】SpringBoot Web开发(八)

    本周介绍SpringBoot项目Web开发的项目内容,及常用的CRUD操作,阅读本章前请阅读[SpringBoot]SpringBoot与Thymeleaf模版(六)的相关内容 Web开发 项目搭建 ...

  4. springboot web开发【转】【补】

    pom.xml引入webjars的官网 https://www.webjars.org/ https://www.thymeleaf.org/doc/tutorials/3.0/usingthymel ...

  5. SpringBoot(四): SpringBoot web开发 SpringBoot使用jsp

    1.在SpringBoot中使用jsp,需要在pom.xml文件中添加依赖 <!--引入Spring Boot内嵌的Tomcat对JSP的解析包--> <dependency> ...

  6. Spring-boot -Web开发

    1).创建SpringBoot应用,选中我们需要的模块: 2).SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置就可以运行起来 3).自己编写业务代码: 文件名的功能 x ...

  7. SpringBoot Web开发(3) WebMvcConfigurerAdapter过期替代方案

    springboot2.0中 WebMvcConfigurerAdapter过期替代方案 最近在学习尚硅谷的<springboot核心技术篇>,项目中用到SpringMVC的自动配置和扩展 ...

  8. SpringBoot——Web开发(静态资源映射)

    静态资源映射 SpringBoot对于SpringMVC的自动化配置都在WebMVCAutoConfiguration类中. 其中一个静态内部类WebMvcAutoConfigurationAdapt ...

  9. [SpringBoot——Web开发(使用Thymeleaf模板引擎)]

    [文字只能描述片段信息,具体细节参考代码] https://github.com/HCJ-shadow/SpringBootPlus 引入POM依赖 <properties> <ja ...

  10. web开发-CORS支持

    一.简介 Web 开发经常会遇到跨域问题,解决方案有:jsonp,iframe,CORS 等等 1.1.CORS与JSONP相比 1.JSONP只能实现GET请求,而CORS支持所有类型的HTTP请求 ...

随机推荐

  1. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_15-webpack研究-webpack-dev-server-程序调试

    webpack把我们的js文件都打包了.所以不能用chrome的调试工具. 打包生成的js文件比较乱无法跟踪. 配置好了以后就可以让浏览器查看到打包后的源代码 在源代码这里加一个debuuger 这里 ...

  2. python 时间类型

  3. linux下maven环境的搭建

    1.maven的下载 2.maven的安装和环境变量配置 系统环境linux centos7.2 x64 1.maven的下载 下载地址:https://mirrors.tuna.tsinghua.e ...

  4. Vue CLI 3 如何自定义 js 的文件名

    参考链接:https://blog.csdn.net/weixin_33979363/article/details/88742342

  5. 第07组 Alpha冲刺(1/4)

    队名:秃头小队 组长博客 作业博客 组长徐俊杰 过去两天完成的任务:完成人员分配,初步学习Android开发 Github签入记录 接下来的计划:继续完成Android开发的学习,带领团队进行前后端开 ...

  6. 洛谷 题解 CF910C 【Minimum Sum】

    当时看到这题一脸懵逼,莫名想到了复杂度为O(10000000000*n)的算法,然而肯定会超时(废话) 算法楼上楼下都说的很清楚了 很明显这题是要用每个字母的权值进行排序.然后依次进行赋值. \(\c ...

  7. mysql导入问题

      今天在导入数据库的时候,发现此问题: 后来一查,是因为GTID_EXECUTED有值,而导出的文件中包含了SET @@GLOBAL.GTID_PURGED的操作,所以导入报错. 我们有两种方法解决 ...

  8. 《MIT 6.828 Lab 1 Exercise 4》实验报告

    本实验链接:mit 6.828 lab1 Exercise 4. 题目 Exercise 4. Read about programming with pointers in C. The best ...

  9. windows 修改Administrator管理员账户名

      用[Win+R]组合键命令打开[运行]界面,输入[gpedit.msc],按[回车键]或[鼠标左键]单击[确定]按钮:   在弹出的[本地组策略编辑器]对话框中,依次[鼠标左键]点击打开:[计算机 ...

  10. ibox 的使用

    <div class="ibox float-e-margins"> <div class="ibox-title"> <h5&g ...