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

启动查看效果:

图标成功显示!

相关推荐
Vfw3VsDKo几秒前
Maui 实践:Go 接口以类型之名,给 runtime 传递方法参数
开发语言·后端·golang
迈巴赫车主34 分钟前
蓝桥杯19724食堂
java·数据结构·算法·职场和发展·蓝桥杯
i220818 Faiz Ul1 小时前
动漫商城|基于springboot + vue动漫商城系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·动漫商城系统
海兰2 小时前
【实战】MCP 服务在 Nacos 中注册状态分析与优化
android·java·github·银行系统·银行ai
是真的小外套2 小时前
第十五章:XXE漏洞攻防与其他漏洞全解析
后端·计算机网络·php
Makoto_Kimur2 小时前
Java 打印模板大全
java·开发语言·排序算法
程序员榴莲2 小时前
Java(十)super关键字
java·开发语言
HAPPY酷2 小时前
Python高级架构师之路——从原理到实战
java·python·算法
ybwycx3 小时前
SpringBoot下获取resources目录下文件的常用方法
java·spring boot·后端
PrDf22Iw83 小时前
CPU ↔ DRAM(内存总线)的可持续数据传输带宽
java·运维·网络