进阶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 目录任意一个包下

启动查看效果:

图标成功显示!

相关推荐
摇滚侠2 分钟前
MyBatis 入门到项目实战 特殊 SQL 的执行 34-37
java·sql·mybatis
鱼人10 分钟前
Go 操作 MySQL:常用写法与最佳实践
后端
挖坑的张师傅13 分钟前
方便 Mac 本机运行 e2b 的沙箱方案 e2b-local
人工智能·后端
开心猴爷15 分钟前
Flutter 如何自动上传 可以 IPA 把构建和上传分开处理
后端·ios
二月龙16 分钟前
defer 执行顺序与底层原理,90% 的人都理解不全
后端
长大198816 分钟前
新手常犯的 Go 语法错误,一次性帮你避坑
后端
小强198816 分钟前
深入理解 Go 协程 Goroutine:并发编程的核心精髓
后端
chengliu050827 分钟前
后端学习地图
后端
phltxy32 分钟前
Spring AI 可观测性与 Zipkin 实战
java·人工智能·spring
兰令水40 分钟前
leecodecode【面试150】【2026.6.13打卡-java版本】
java·算法·leetcode