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

启动查看效果:

图标成功显示!

相关推荐
一诺加油鸭14 分钟前
若依后端系统集成 Swagger 接口文档功能
java·开发语言
云烟成雨TD19 分钟前
Spring AI Alibaba 1.x 系列【40】多智能体核心模式 - 智能体作为工具(Agent as Tool)
java·人工智能·spring
测试员周周31 分钟前
【踩坑系列3】飞书机器人集体“失联“?3 个 Gateway 进程让我差点崩溃!一个测试老兵的排查实录
java·python
aq553560032 分钟前
Laravel9.x新特性全解析
java·开发语言·数据库
齿轮33 分钟前
Agent 管理范式演进:从管一句话到管整个系统
人工智能·后端
亦暖筑序36 分钟前
AI 客服系统升级实战:多 Agent 路由 + 多轮记忆 + 敏感词过滤
java·后端
啷咯哩咯啷41 分钟前
纯本地运行的私人文档知识库
前端·人工智能·后端
Determined_man41 分钟前
项目中异常什么时候打印错误和抛出?
后端
zhangzeyuaaa44 分钟前
深入理解 Python GIL:从机制到释放时机
java·网络·python
阿丰资源1 小时前
基于SpringBoot的房产销售系统设计与实现(附源码+数据库+文档,一键运行)
数据库·spring boot·后端