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

启动查看效果:

图标成功显示!

相关推荐
想不到一个好的ID几秒前
Redis 高可用:主从复制详解
后端
爪哇碎碎念14 分钟前
【Java】从一次 cache.get(key) 进去:缓存击穿一瞬间打出 200 次 DB,JDK 17 实测三种解法
java·redis·缓存
csdn_aspnet14 分钟前
Java 使总距离最短的最佳点位置(Optimum location of point to minimize total distance)
java·算法
源码_空间21 分钟前
基于Springboot的在线编程练习判题平台(源码+文档)
java·spring boot·后端
码事漫谈35 分钟前
当了领导才知道,有些时候,骂人的话真的忍不住
后端
程序员cxuan1 小时前
再见 Claude,国模 SOTA 模型来了
人工智能·后端·程序员
程序员cxuan1 小时前
夯爆了,影视界的 Codex 来了!
人工智能·后端·程序员
孟健1 小时前
抖音官方 CLI 上线:一句话搜同行爆款、扒文案,实测全记录
后端·ai编程
小手cool2 小时前
二分查找:在有序数组中查找最接近 target 的元素索引
java·数据结构·算法
烬中寻道2 小时前
GoFrame + Trae:把数据库凭据从配置文件里彻底拿掉
后端