SpringBoot Web开发的方法

发布时间:2022-03-03 15:43:24 作者:iii
来源:亿速云 阅读:79

本篇内容主要讲解“SpringBoot Web开发的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“SpringBoot Web开发的方法”吧!

一、简介

1.1 引入SpringBoot模块

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

  1. xxxxAutoConfiguration:帮我们给容器中自动配置组件;

  2. xxxxProperties:配置类来封装配置文件的内容;

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

SpringBoot Web开发的方法

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
"classpath:/META‐INF/resources/", 
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/"
"/":当前项目的根路径

示例

localhost:8080/abc # 去静态资源文件夹里面找abc

示例: localhost:8080/ 找index页面

二、模版引擎

2.1 简介

原理图如下:

SpringBoot Web开发的方法

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";
    // ....省略...
}
<htmllang="en"xmlns:th="http://www.thymeleaf.org">

到此,相信大家对“SpringBoot Web开发的方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. springboot新手入门教程
  2. springBoot(9):web开发-CORS支持

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot web

上一篇:springboot时间戳和数据库时间相差多少个小时

下一篇:Springboot热部署的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》