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

启动查看效果:

图标成功显示!

相关推荐
plainGeekDev8 分钟前
synchronized → Coroutines
android·java·kotlin
Lyra_Infra12 分钟前
故障排查报告:Spring boot连接 Nacos 异常及启动失败
java·spring boot
星栈独行16 分钟前
Node 框架怎么选?Express、Koa、Egg、NestJS 场景化选型指南
后端·程序人生·node.js
liguojun202521 分钟前
智慧文体旅系统选哪家?豆米跳跳十年技术沉淀支持源码交付
java·大数据·人工智能·物联网·1024程序员节
你为她披上外套时我正站在窗外27 分钟前
拆解 siwi-download:Rust 异步下载器是怎么炼成的
后端
苍何32 分钟前
WAIC深度体验:能跨端使用的 Agent 才是好 Agent!
后端
学习使得吾快乐1 小时前
时序数据库 TDengine 在设备监测中的实际落地:从传感器上报到实时看板
java·时序数据库·tdenginne
程序员清风1 小时前
推荐几个我常听的AI播客!
java·后端·面试
唐青枫1 小时前
Java Gradle 实战指南:从 Wrapper、Kotlin DSL 到 Spring Boot 多模块构建
java·kotlin·gradle
JavaGuide2 小时前
Kimi K3 实战:全栈项目、Java 项目改造与 3A 游戏 Demo
后端·ai编程