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

启动查看效果:

图标成功显示!

相关推荐
Jooou13 分钟前
Spring事务实现原理深度解析:从源码到架构全面剖析
java·spring·架构·事务
dreams_dream33 分钟前
Flask
后端·python·flask
盖世英雄酱5813639 分钟前
commit 成功为什么数据只更新了部分?
java·数据库·后端
追逐时光者1 小时前
小伙伴们学习 C#/.NET 相关技术栈的学习心得和路线
后端·.net
gelald1 小时前
Spring Security 核心组件
后端·spring
码上淘金1 小时前
在 YAML 中如何将 JSON 对象作为字符串整体赋值?——兼谈 Go Template 中的 fromJson 使用
java·golang·json
码事漫谈1 小时前
Blazor现状调研分析:2025年全栈开发的新选择
后端
码事漫谈1 小时前
C++的开发难点在哪里?
后端