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

启动查看效果:

图标成功显示!

相关推荐
这个昵称不容易32 分钟前
租房管理系统设计与实现:16 张表、185 个接口的 SpringBoot 前后台项目
java·springboot·毕设
Thanks_ks1 小时前
RESTful API 到底是什么:从 URL 设计讲到请求方法的选择
spring boot·http·状态码·url·幂等性·restful api·无状态
狗头大军之江苏分军1 小时前
《潮水漫过十七岁》 加一个蛋,顺便说一下我解放了
前端·后端
Captaincc1 小时前
掘金AI用量迎来重大更新!全新AI用量
前端·后端
nice_lcj5202 小时前
Spring 事务:声明式事务怎么生效
java·spring·面试·事务·transactional·传播机制
沐知全栈开发2 小时前
基于Flask的班级信息与班务管理系统设计与实现-毕业设计
java·flask·课程设计
AAA修煤气灶刘哥2 小时前
排查一次 CI 失败,Cloudflare 怎么把六次大模型调用减到一次?
人工智能·后端·llm
RobinXYuan2 小时前
【Java 字节码探秘】04 总览:索引空间与 17 种 cp_info
java·jvm·源码阅读
vx-程序开发2 小时前
【毕设分享】05253基于Spring+Boot的作业提交与管理系统的设计与实现
java·spring boot·后端·spring·源码·课程设计·大作业
Rain的Java大神之路3 小时前
把 ThreadLocal 换成 ScopedValue 后,请求上下文为什么在子线程里"消失"了?三个边界 + 完整迁移指南(JDK 25)
java·后端·面试