springboot 设置ico_Spring Boot--Thymeleaf模板引擎/静态页面

点关注,不迷路;持续更新Java相关技术及资讯!!!

9effed5d-d46a-4ce7-b46c-e6472d4dafcd

1.Spring Boot对静态资源的映射规则

  • 如果静态资源文件夹下有 index.html的话,直接访问localhost:8080的话,index就是欢迎页

使用自己的图标:

8697f8475a814beb9b17c7c11d2994b1

在静态资源文件夹放一个 favicon.ico 的图标,springboot底层会自动调用这个为我们的图标

bbfcb66ca85846dda63513ca40e58154

我找了个小叮当的图标

效果:

7698617ebd754ed3b24d60b846815fa7

自定义静态资源文件夹

在你的 yml/properties下添加:

spring.resources.static-locations=classpath:/hello/,classpath:/carson/

定义之后,原来默认的就不可以使用了

2. 引入 Thymeleaf

SpringBoot推荐使用thymeleaf,因为语法简单,功能强大, 不推荐使用jsp,默认也不支持jsp

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

新版本的Spring Boot会自动设置好版本,如果你是1.x的Spring Boot,可能要自己更改版本了

3. Thymeleaf 使用&语法

源码:

@ConfigurationProperties( prefix = "spring.thymeleaf")public class ThymeleafProperties { private static final Charset DEFAULT_ENCODING; public static final String DEFAULT_PREFIX = "classpath:/templates/"; public static final String DEFAULT_SUFFIX = ".html"; private boolean checkTemplate = true; private boolean checkTemplateLocation = true;  // 下面是前后缀,也就是说只要放在 prefix 目录下,就可以被渲染了 private String prefix = "classpath:/templates/"; private String suffix = ".html";
  1. 写一个 controller 方法:
 @RequestMapping("nice") public String nice(){ return "nice"; }
  1. 在 resources下的 templates目录下创建nice.html
 Title

这是 nice 标签

  1. 启动程序,访问 localhost:8080/nice
b688513520fc4621a3fe556a2791909d

使用:

1.html页面 导入 thymeleaf 的名称空间

2.使用thymeleaf语法

  • controller:
 @RequestMapping("nice") public String nice(Map map){ map.put("hello
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值