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

启动查看效果:

图标成功显示!

相关推荐
燕-孑14 分钟前
tomcat详解(基础到高级生产)
java·tomcat
码不停蹄的玄黓22 分钟前
Spring Bean 生命周期
java·后端·spring
西安邮电大学34 分钟前
分治算法详细讲解
java·后端·其他·算法·面试
摇滚侠43 分钟前
Mybatis 入门到项目实战 搭建 MyBatis 框架 01-14
java·tomcat·mybatis
老马聊技术1 小时前
AI对话功能之SpringBoot整合Vue3
vue.js·人工智能·spring boot·后端
武子康1 小时前
调查研究-174 什么是“红丸主义“:它为什么吸引人,又为什么容易把人带偏?
后端
神奇小汤圆1 小时前
白嫖DeepSeek V4 Pro!免费无限用,还能接入Claude-Code
后端
码不停蹄的玄黓1 小时前
SpringBoot 全局异常处理器实现
java·spring boot·后端
JS菌2 小时前
Skills 动态加载系统:让 AI Agent 按需获取领域知识
前端·人工智能·后端
神奇小汤圆2 小时前
Vector Graph RAG 开源!一套向量数据库同时搞定语义检索+RAG多跳
后端