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

启动查看效果:

图标成功显示!

相关推荐
稽稽稽稽不如人几秒前
《从零开始的java从入门到入土的学习生活——Java后端篇》Chapter21——Java后端篇学习记录——Redis初步入门
java·学习·生活
ID_180079054734 分钟前
淘宝店铺所有商品 API 接口:核心能力与数据返回参考
java·服务器·前端
鹏程十八少13 分钟前
13. Android 面了50位Kotlin候选人,这36个语法坑90%的人答不全
前端·后端·面试
轻刀快马17 分钟前
浅聊Java反射
java·开发语言
Gerardisite17 分钟前
企业微信智能客服开发实战:API自动回复指南
java·开发语言·python·机器人·企业微信
东宇科技18 分钟前
用CladueCode来玩tp8+swoole(常用案例)
后端·swoole
要开心吖ZSH19 分钟前
零基础入门 Spring WebFlux 与 Project Reactor:从小白到顿悟
java·响应式编程·spring webflux
智塑未来19 分钟前
装备制造行业设计制造一体化痛点攻克与实战经验总结
java·开发语言·制造
Shadow(⊙o⊙)23 分钟前
硬核手搓解析!进程-内核分析:命令行参数及环境变量,重构main()
linux·运维·服务器·开发语言·c++·后端·学习
Devin~Y25 分钟前
电商AIGC智能客服面试:JVM调优、Spring Cloud微服务、Redis缓存、Kafka消息、K8s观测与RAG落地
java·jvm·spring boot·redis·spring cloud·kafka·kubernetes