1.如图:目录为如下,
2.首先是index.ftl配置访问static的静态文件,按住ctrl可以点过去,但是运行起来在chrome中报404,觉得很纳闷,
<div class="logo"><a href=""><img src="/assets/img/logo-partner-01.png" alt=""></a></div>
<div class="logo"><a href=""><img src="/static/assets/img/logo-partner-02.png" alt=""></a></div>
<div class="logo"><a href=""><img src="/static/assets/img/logo-partner-03.png" alt=""></a></div>
<div class="logo"><a href=""><img src="/static/assets/img/logo-partner-04.png" alt=""></a></div>
<div class="logo"><a href=""><img src="/static/assets/img/logo-partner-05.png" alt=""></a></div>
然后再网上找答案答案如下:
但是为什么idea会提示无法定位资源呢,因为springboot默认的动态文件目录是templates,所以在查找时是从templates目录开始,但是templates目录得文件外界是无法直接访问的。这里我们需要把静态资源文件放在static文件目录下,这个目录外界是可以直接访问的,虽然idea提示找不到文件,但程序在运行后是正常访问的。
原文:https://blog.csdn.net/Tomsidi/article/details/83041244
解决方法:1,之后改成如下,完美运行
2,或者不用改,直接添加配置#设定静态文件路径,js,css等 spring.mvc.static-path-pattern=/static/**
<div class="logo"><a href=""><img src="/static/assets/img/logo-partner-01.png" alt=""></a></div>
<div class="logo"><a href=""><img src="/assets/img/logo-partner-02.png" alt=""></a></div>
<div class="logo"><a href=""><img src="/assets/img/logo-partner-03.png" alt=""></a></div>
<div class="logo"><a href=""><img src="/assets/img/logo-partner-04.png" alt=""></a></div>
<div class="logo"><a href=""><img src="/assets/img/logo-partner-05.png" alt=""></a></div>