51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Thymeleaf Error resolving template [favicon.ico]

每一个看似简单的社会现象其实都只露出了冰山一角。------林达

遇到这个报错,方案1:

在页面上添加:

|-----------|---------------------------------------------------------------| | 1 | hljs html <link rel="icon" href="/static/favicon.ico"> |

前提是你有icon并且放到了static下面

image-20211217174528333

方案2:

写个过滤器,给它过滤掉

|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | hljs java package com.ruben.simplescaffold.filter; import cn.hutool.core.lang.Opt; import cn.hutool.core.text.CharSequenceUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.Arrays; import java.util.List; /** * 过滤器 * * @author <achao1441470436@gmail.com> * @since 2021/8/4 17:09 */ @Slf4j @Component @WebFilter(filterName = "faviconFilter", urlPatterns = "/**") public class UserAgentFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; String uri = httpRequest.getRequestURI(); if (uri.contains(FAVICON)) { // 过滤图标 response.getWriter().write(CharSequenceUtil.EMPTY); return; } chain.doFilter(request, response); } } |

方案3:

写一个接口,返回空

|------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | hljs java package com.ruben.simplescaffold.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * @author <achao1441470436@gmail.com> * @since 2021/7/11 0011 16:22 */ @Controller public class IndexController { /** * 图标 */ @GetMapping({"favicon.ico", "favicon"}) @ResponseBody public void favicon() { } } |

赞(0)
未经允许不得转载:工具盒子 » Thymeleaf Error resolving template [favicon.ico]