栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot themleaf

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot themleaf

文章目录

如何阅读与分析源码1:如何导入静态资源2:访问html以及更改图标3:通过controller跳转到首页4:如何使用thymeleaf5:thymeleaf语法6:自动装配原理,告诉MVC我想定制一些什么。7:视图跳转
xxxxAutoConfiguration:向容器中自动配置组件

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

如何阅读与分析源码

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

1:如何导入静态资源

引入web-jars与jQuery

   
            org.webjars
            jquery
            3.4.1
        

访问webjars下的路径

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

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

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

所以访问静态资源可以在

webjars

resource/static/public/ /**

优先级:resources>static>public

2:访问html以及更改图标

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

更改图标:

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

在html中引入

访问localhost:8081/index.html

3:通过controller跳转到首页

导入Thymeleaf

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

 
            org.springframework.boot
            spring-boot-starter-thymeleaf
        

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

访问链接

4:如何使用thymeleaf

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


变量:${…}

选择表达式:*{}

message:#{}

链接 @{}

fragment:-{}

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

注ctrl+f5可以去除缓存

5:thymeleaf语法

1:转义识别标签 th:utext

2:遍历数组

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

其他方式:

[[${users}]]

装配扩展: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;
        }
    }

}

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”);
}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/716079.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号