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

启动查看效果:

图标成功显示!

相关推荐
潍坊老登几秒前
什么?我的官网最近流量异常增加?
后端
CoderYanger35 分钟前
Java EE 进阶:12.Spring AOP(第二弹)
java·前端·数据库·spring boot·spring·java-ee·mybatis
利威尔xu1 小时前
2026-11-24-Go限流器实战
后端·golang
CoderYanger2 小时前
Java EE 进阶:12.Spring AOP(第一弹)
java·开发语言·spring boot·后端·spring·java-ee·交互
H H.2 小时前
Java笔记:String字符串
java·开发语言·经验分享·笔记·其他
Rain的Java大神之路3 小时前
Spring AI 还是 LangChain4j?2026 年 Java 接入大模型,我把这笔「架构赌注」的账算清楚了
java·后端·ai编程
用户112936112193 小时前
注释掉的接口为什么还能访问?没有 Git 也能证明改动有没有进产物
java
Csvn3 小时前
Nginx 高可用网关:VIP 切换、proxy_protocol 与 SNI 分流实战
后端·nginx
Gopher_HBo3 小时前
跟着一次导出,走完 runtime/pprof:从一张工单到一份文件
后端
sharemylove3 小时前
Java 异常处理 学习笔记
java·开发语言·经验分享·笔记·学习