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

启动查看效果:

图标成功显示!

相关推荐
蜜獾云9 分钟前
JAVA面试题速记-redis知识点
java·开发语言·redis
Dragon Wu12 分钟前
SpringCache 缓存使用总结
spring boot·后端·spring·缓存·springcloud
Drifter_yh19 分钟前
「JVM」 深入理解 StringTable:从底层编译优化到 intern 核心解密
java·jvm
夜瞬29 分钟前
【Flask 框架学习】01:编写第一个 Flask 应用
后端·python·学习·flask
JavaLearnerZGQ29 分钟前
Spring Boot 流式响应接口核心组件解析
java·spring boot·后端
cur1es30 分钟前
【TCP 协议的相关特性】
java·网络·网络协议·tcp/ip·tcp·滑动窗口·连接管理
春和景明36032 分钟前
springboot
spring boot·spring
山岚的运维笔记34 分钟前
SQL Server笔记 -- 第80章:分页
java·数据库·笔记·sql·microsoft·sqlserver
Loo国昌37 分钟前
【AI应用开发实战】07_文档解析路由与质量评估:从传统PDF解析到Docling现代化方案
人工智能·后端·python·自然语言处理·pdf
Pr Young39 分钟前
有限状态机
服务器·后端