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

启动查看效果:

图标成功显示!

相关推荐
Achou.Wang5 分钟前
Concurrency patterns - Go 并发模式
开发语言·后端·golang
存在morning5 分钟前
【GO语言开发实践】三 GO 工程化快速上手
开发语言·后端·golang
devilnumber7 分钟前
如何在java的Lambda中安全地修改外部变量?
java·安全·lambda
大得3698 分钟前
langchain使用
java·python·langchain
带刺的坐椅9 分钟前
SolonCode CLI 的心智记忆功能:让 AI 编程助手越用越懂你
java·ai·llm·cli·soloncode
我命由我1234519 分钟前
Visual Studio - Visual Studio 注释快捷键
java·c语言·开发语言·c++·ide·java-ee·visual studio
lemon_sjdk26 分钟前
DecimalFormat
java·开发语言·python
Nontee30 分钟前
一、Java 基础 面试题解答(72题)
java·开发语言
兰令水31 分钟前
topcode【随机算法题】【2026.5.16打卡-java版本】
java·数据结构·算法
摇滚侠31 分钟前
SpringBoot 面试题 真正的 offer 偏方 Java 基础 Java 高级
java·spring boot·后端