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

启动查看效果:

图标成功显示!

相关推荐
逆境不可逃1 分钟前
Pi Agent 学习笔记:一次提问背后的工具调用循环
java·笔记·学习
落魄大学生之流水线上谋生计4 分钟前
Java并发核心机制详解:线程池、CAS、AQS、锁升级
java·开发语言·数据库
aosky18 分钟前
Linux 写内容到文件的几种方式
java·linux·服务器
苍何24 分钟前
小米版 Codex,干活有点猛啊
后端
苍何35 分钟前
直播!用 AI 实时生成游戏,速来看
后端
Wang's Blog38 分钟前
Java框架快速入门: Spring Security+OAuth2之邮件验证码发送(SMTP与API方式)
java·数据库·spring
苍何1 小时前
免费版 Typeless来了,不限额度,夯!
后端
砚底藏山河2 小时前
容错重试与指数退避:网络抖动手抖不再丢数据(魔码量化实战 #04)
java·数据库·python·金融
Charlie_Byte2 小时前
Integer 缓存机制(JDK 17 源码)
后端
梨涡泥窝2 小时前
JavaWeb——基于 Spring Boot + Vue 的图书管理系统的设计与实现
vue.js·spring boot·后端