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

启动查看效果:

图标成功显示!

相关推荐
郭小李2 分钟前
spring mvc 工作流程
java·spring·mvc
苍何10 分钟前
开源微信流 APP,手机微信聊天记录,可以直接给 WorkBuddy 和 Obsidian 了
后端
SL_staff26 分钟前
BI大屏嵌入MES的登录态难题:JVS统一账号体系实战解法
java·数据分析·数据可视化
智驭未来掌门人30 分钟前
Qt 项目不建议导入 CLion 说明
后端
乌暮34 分钟前
综合案例:宠物电商系统
java·开发语言·spring·mvc·restful·1024程序员节
Lumos_38 分钟前
P1 签名 (PKCS#1) vs 裸签 (Raw Signature)
后端
今天早睡41 分钟前
调用真实模型,用 Pydantic 校验后再路由
后端
VimorphTech42 分钟前
一段字幕太长,怎样拆句并安排显示时间?
java·spring boot
万联WANFLOW43 分钟前
Kimi K3.1 Pro 接口接入指南:模型选型、费用计算与零数据保留
java·spring boot·python·安全·spring·大模型
智驭未来掌门人43 分钟前
CLion 创建并运行 Qt 项目指南
后端