Springboot-web篇---part01-webjars

SpringBoot对静态资源的映射规则

1.所有/webjars/**,都去classpath:/META-INF/resources/webjars/找资源;
webjars:以jar包的方式引入静态资源;
https://www.webjars.org/
引入静态资源jquary-webjars

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.4.1</version>
        </dependency>

2.“/**”访问当前项目的任何资源,(静态资源的文件夹)


"classpath:/META-INF/resources/",
"classpath:/recources/",
"classpath:/static/",
"classpath:/public/"
"/":当前项目的根路径

例:localhosts:8080/abc ===去静态资源文件夹里找abc
3.欢迎页:静态资源文件夹下所有的index.html
页面;“/**”映射;
localhost:8080/ 找index页面

4.(图标)所有的**/favicon.ico 都是在静态资源文件下找

模板引擎

jsp,Velocity,Freemaker,Thymeleaf
SpringBoot推荐Thymeleaf

1.引入thymeleaf

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>2.2.4.RELEASE</version>
    </dependency>

2.Thymeleaf使用和语法

只要把HTML页面放在classpath:/templates/,thymeleaf就能自动渲染;
使用:
1.导入Thymeleaf的名称空间

<html lang="en" xmlns:th="http://thymeleaf.org">

2.使用Thymeleaf

3.语法规则

1.在这里插入图片描述
2.表 达式
${ , }:获取变量值

  • 获取对象的属性,调用方法
  • 使用内置的基本对象
  • 内置的一些工具对象
    ** *{ , } **:选择表达式:和${ }在功能上是一样的
    补充:配合 th:object="{session.user}"
    #{ , } 获取国际化内容
    @{ , } 定义URL
    ~{ , } 片段引用表达式
    Arithmetic operations:(数学运算)
发布了43 篇原创文章 · 获赞 6 · 访问量 1528

猜你喜欢

转载自blog.csdn.net/weixin_43729631/article/details/104620643