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

启动查看效果:

图标成功显示!

相关推荐
咖啡八杯10 小时前
GoF设计模式——策略模式
java·后端·spring·设计模式
lizhongxuan11 小时前
AI Agent 上下文压缩利器 Headroom
后端
Csvn13 小时前
SSH 远程管理与安全加固 — 运维的守门之道
后端
IT_陈寒13 小时前
Python搞不定字符串编码?这破玩意坑我两小时!
前端·人工智能·后端
菜鸟谢14 小时前
Rust 智能指针完整详解
后端
java小白小14 小时前
SpringBoot(01): 初识SpringBoot,从Spring的痛点说起
spring boot
菜鸟谢15 小时前
Rust 函数完整知识点详解
后端
爱勇宝15 小时前
淡泊名利之前,先承认我们都很焦虑
前端·后端·程序员
菜鸟谢15 小时前
Rust 闭包(Closure)完整详解
后端
ServBay15 小时前
如何利用本地技术栈构建 0 成本 AI SaaS 雏形
后端·aigc·ai编程