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

启动查看效果:

图标成功显示!

相关推荐
aiopencode1 分钟前
iOS 应用上架的工程实践复盘,从构建交付到审核通过的全流程拆解
后端
在逃热干面2 分钟前
(笔记)获取终端输出保存到文件
java·笔记·spring
爱笑的眼睛113 分钟前
深入理解MongoDB PyMongo API:从基础到高级实战
java·人工智能·python·ai
笃行客从不躺平13 分钟前
遇到大SQL怎么处理
java·开发语言·数据库·sql
q***876020 分钟前
Spring Boot 整合 Keycloak
java·spring boot·后端
Billow_lamb21 分钟前
Spring Boot2.x.x全局拦截器
java·spring boot·后端
上不如老下不如小31 分钟前
2025年第七届全国高校计算机能力挑战赛初赛 Java组 编程题汇总
java·计算机能力挑战赛
泉城老铁1 小时前
Springboot对接mqtt
java·spring boot·后端
源码_V_saaskw1 小时前
JAVA国际版同城跑腿源码快递代取帮买帮送同城服务源码支持Android+IOS+H5
android·java·ios·微信小程序
TT哇1 小时前
消息推送机制——WebSocket
java·网络·websocket·网络协议