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

启动查看效果:

图标成功显示!

相关推荐
kfaino12 小时前
码农的AI翻身(五)你好,我叫 Transformer
后端·aigc
Oneslide18 小时前
机械革命 单系统纯净重装Ubuntu(全盘覆盖,清空原有Windows)
后端
GetcharZp18 小时前
告别OOM!用Go+libvips实现30000×50000超大图片的流式瓦片服务
后端·go
IT_陈寒18 小时前
JavaScript项目实战经验分享
前端·人工智能·后端
用户479492835691519 小时前
6w star,GitHub 趋势第一的 Ponytail,这个agent插件到底在火什么
前端·后端
吃饱了得干活20 小时前
Spring Cloud Gateway 微服务网关:路由、断言、过滤器
java·spring cloud
神奇小汤圆20 小时前
2026一线大厂Java八股文精选(附答案,高质量整理)
后端
Warson_L21 小时前
LangGraph入门学习资料
后端
神奇小汤圆21 小时前
Spring Boot → Solon 注解迁移实战指南:一张对照表说清楚
后端
kfaino21 小时前
码农的AI翻身(四)你好,我叫 Attention
人工智能·后端