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

启动查看效果:

图标成功显示!

相关推荐
MY_TEUCK1 分钟前
从零开始:使用Sealos Devbox快速搭建云原生开发环境
人工智能·spring boot·ai·云原生·aigc
覆东流1 分钟前
第4天:Python输入与输出
后端·python·photoshop·输入与输出
摇滚侠6 分钟前
Java Map 类型的数据可以存储到 Redis Hash 类型中
java·redis·哈希算法
人道领域20 分钟前
【LeetCode刷题日记】:151翻转字符串的单词(两种解法)
java·开发语言·算法·leetcode·面试
lifallen23 分钟前
Flink 深度解析:从 TM、Task、Operator、UDF 到 Mailbox 与 OperatorChain
java·大数据·flink
Seven9724 分钟前
【从0到1构建一个ClaudeAgent】协作-Worktree+任务隔离
java
XS03010624 分钟前
Java 基础(五)值传递
java·开发语言
倒霉蛋小马25 分钟前
SpringBoot3中配置Knife4j
java·spring boot·后端
我叫黑大帅28 分钟前
从零实现一个完整 RAG 系统:基于 Eino 框架的检索增强生成实战
后端·面试·go
NotFound48629 分钟前
实战分享怎样实现Spring Boot 中基于 WebClient 的 SSE 流式接口操作
java·spring boot·后端