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

启动查看效果:

图标成功显示!

相关推荐
idolao35 分钟前
Oligo 7.60 安装教程:引物设计+Java 环境配置
java·开发语言
做个文艺程序员4 小时前
第04篇:K8s 弹性伸缩实战:HPA、VPA、KEDA——Java SaaS 应对流量洪峰的秘密武器
java·容器·kubernetes·弹性伸缩·自动扩容·ai 推理伸缩
木雷坞5 小时前
Go 项目实战:用 MLiev IAM 落地企业认证中心
后端·golang·认证
石山代码7 小时前
ArrayList / HashMap / ConcurrentHashMap
java·开发语言
AskHarries9 小时前
系统提示词、开发者指令和用户输入的优先级
java·前端·数据库
Moment9 小时前
长上下文会最终杀死 Rag 吗?
前端·javascript·后端
daidaidaiyu9 小时前
ThingsBoard 规则链系统源码分析和自定义定时器
java
蝎子莱莱爱打怪10 小时前
🚀 🚀🚀2026年5月GitHub月榜精选:17个项目中挑出10个推荐,实操4个!
人工智能·后端·ai编程
小毛驴85010 小时前
spring-boot-maven-plugin,maven-compiler-plugin 功能对比
java·python·maven
csdn_aspnet10 小时前
Java 霍尔分区算法(Hoare‘s Partition Algorithm)
java·开发语言·算法