进阶SpringBoot之首页和图标定制

idea 快捷键:

ctrl + shift + "+" 使缩起来的代码展开

ctrl + shitf + "-" 使代码缩起

WebMvcAutoConfiguration.class:可以看到需要有一个 index.html 文件映射到首页

java 复制代码
        private Resource getIndexHtmlResource(Resource location) {
            try {
                Resource resource = location.createRelative("index.html");
                if (resource.exists() && resource.getURL() != null) {
                    return resource;
                }
            } catch (Exception var3) {
            }

            return null;
        }

resources 目录下 任意一个(图片上有的)都能存放 index.html,随便写个首页两字

(放在 templates 目录下的所有页面,只能通过 controller 来跳转)

如果放在 templates 包下,需要有 thymeleaf 插件

java 复制代码
package com.demo.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {
    //在templates目录下的所有页面,只能通过controller来跳转
    @RequestMapping ("/index")
    public String index(){
        return "index";
    }
}

同理,把图片命名为 favicon.ico,放到 resources 目录任意一个包下

启动查看效果:

图标成功显示!

相关推荐
掘金者阿豪5 分钟前
高可用读写分离实战(二):我把数据库主库停了,结果整个集群的反应和我想象的不一样
后端
掘金者阿豪7 分钟前
《高可用读写分离集群实战》系列(一)
后端
Dilee22 分钟前
Spring AI 2.0.0 Prompt 最小 Demo:system、user、template 到底怎么分工
后端
未秃头的程序猿28 分钟前
Java 26正式发布!这3个新特性,让代码量直接减半
java·后端·面试
小旭Coding1 小时前
卧靠!Go 传给前端的 int64 竟然变成了这个?
后端
用户298698530141 小时前
Word 文档文本查找与替换的 Java 实现方案
java·后端
阿哉1 小时前
Nacos 服务发现源码:藏在背后的两套事件机制,90%的人只讲了一半
java
kunge20131 小时前
深度剖析Claude Code 的CLAUDE.md加载逻辑
后端·vibecoding