springboot themleaf


xxxxAutoConfiguration:向容器中自动配置组件

xxxxProperties:自动配置类,装配配置文件中自定义的一些内容。

如何阅读与分析源码

Ctrl+n表示搜索全局包括类

1:如何导入静态资源

引入web-jars与jQuery

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

访问webjars下的路径

访问localhost:8081/webjars/jquery/3.1.4/jquery.js

image-20220114222248667

image-20220114222559191

可以存放静态资源的目录:

image-20220114223405548

image-20220114223440972

访问http://localhost:8081/1.js

image-20220114223510942

所以访问静态资源可以在

webjars

resource/static/public/ /**

优先级:resources>static>public

2:访问html以及更改图标

只需要将index.html放入上述任意的文件中即可

更改图标:

找到图片将后缀改为a.ico,并将图标放入html同级目录

在html中引入

image-20220115221633961

访问localhost:8081/index.html

image-20220115221746629

3:通过controller跳转到首页

导入Thymeleaf

因为是2.6.2的springboot,所以导入的依赖为:

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

image-20220117205724993

选择目录创建html文件,并在controller中写上方法

image-20220117210304344

访问链接

image-20220117210404379

4:如何使用thymeleaf

1:需要在html开头导入约束

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

变量:${…}

选择表达式:*{}

message:#{}

链接 @{}

fragment:-{}

使用:如果爆红检查注解一定要是Controller

image-20220117215030319

image-20220117221720830

注ctrl+f5可以去除缓存

5:thymeleaf语法

1:转义识别标签 th:utext

image-20220117224744836

image-20220117224808846

2:遍历数组

model.attriubute(“user”,Array.aslist(“sheepbotany”,"woodwhale));//将字符串转化为数组

<h1 th each="users=${user}" th:text="${users}"></h3>

image-20220118144334429

image-20220118144400685

其他方式:

<h3 th:each="users:${user}">[[${users}]]</h3>

装配扩展:SpringMVC

· 简单表达式 (simple expressions)

${…} 变量表达式

*{…} 选择变量表达式

#{…} 消息表达式

@{…} 链接url表达式

· 字面量

‘one text’,‘another one!’,… 文本

0,34,3.0,12.3,… 数值

true false 布尔类型

null 空

one,sometext,main 文本字符

· 文本操作

+ 字符串连接

|The name is ${name}| 字符串连接

· 算术运算

+ , - , * , / , % 二元运算符

- 负号(一元运算符)

· 布尔操作

and,or 二元操作符

!,not 非(一元操作符)

· 关系操作符

> , < , >= , <= (gt , lt , ge , le)

== , != (eq, ne)

· 条件判断

(if) ? (then) if-then

(if) ? (then) : (else) if-then-else

6:自动装配原理,告诉MVC我想定制一些什么。

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    
    @Bean
    public ViewResolver myViewResolver(){
        return new MyViewResolver();
    }

    public static class MyViewResolver implements ViewResolver{

        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {
            return null;
        }
    }

}

image-20220119194748441

7:视图跳转

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

   @Override
    public void addViewControllers(ViewControllerRegistry registry){
       registry.addViewController("/demo02").setViewName("test");
   }

}

figuration
public class MyMvcConfig implements WebMvcConfigurer {

@Override
public void addViewControllers(ViewControllerRegistry registry){
registry.addViewController("/demo02").setViewName(“test”);
}

}


  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值