springboot结合thymeleaf插入背景图片

问题描述:

做首页的时候想做一个背景图片。然后使用thymeleaf模板不知道怎么弄了,网上找了好多资料,发现不好使。

原因分析:

我们的html在templates下,我们的js,css在static目录下,这里就不同于静态资源那样把所有的东西都放在static下那样直接访问。

static下的代码:

<div class="detail" style="background-image: url(img/img1.jpg)"></div>

解决方案:

templates下的html代码:环境springboot2.3.5,thymeleaf3.0

<!-- thymeleaf约束 -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<div class="detail" style="background-image: url(${img/changandaxue.jpg})"></div>

版权声明:本文为weixin_38568503原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。