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

启动查看效果:

图标成功显示!

相关推荐
其美杰布-富贵-李33 分钟前
Spring Boot 依赖注入说明文档
java·spring boot·python
tachibana238 分钟前
hot100 数组中的第K个最大元素(215)
java·数据结构·算法·leetcode
our_times42 分钟前
2026年Java开发者破局指南:Spring AI 2.0 与 Agent 开发实战
java·人工智能·spring
程序员cxuan1 小时前
离谱,GPT-5.6 竟然在后台执行了 rm -rf
人工智能·后端·程序员
Csvn1 小时前
📊 SQL 入门 Day 9:CTE(公用表表达式)— 让 SQL 像写代码一样优雅
后端·sql
运维行者_1 小时前
如何查看每个IP的带宽使用情况?NetFlow 技术实战指南
开发语言·网络·分布式·后端·架构·带宽
流烟默1 小时前
SpringBoot应用链路追踪 traceId 技术方案
spring boot·skywalking·traceid
济*沧*海1 小时前
如何判断接口的返回值?
后端
糖果店的幽灵1 小时前
langgraph的四种state解析
java·前端·javascript·langgraph
杨充1 小时前
5.多用组合和少继承
后端