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

启动查看效果:

图标成功显示!

相关推荐
前端小万1 分钟前
想做个人副业别乱买服务器!我的 5 个月真实开销分享
前端·后端·github
sunburn-2 分钟前
数据库聚合查询完整教程:从基础函数到实战统计
java·数据库·mysql·数据库开发
wangchunyu1149 分钟前
JAVA 类加载机制与双亲委派模型
java·开发语言
小蒜学长23 分钟前
基于 Spring Boot 的英语单词背诵系统的设计与实现(代码+数据库+LW)
java·数据库·spring boot·后端
用户693717500138424 分钟前
我买的电视,我还不能研究它吗?
前端·后端·ai编程
lambo mercy31 分钟前
持久化01——线程级持久化
java·开发语言·jvm
CoderYanger33 分钟前
Java EE 进阶:5. Spring IoC&DI(第一弹):Spring IoC
java·开发语言·spring boot·spring·面试·职场和发展·java-ee
利威尔xu1 小时前
RAG 检索面试十连问:召回率从 92% 掉到 61%,答案句被拦腰截断怎么排查
人工智能·后端·大模型·向量数据库·rag
zyseo81 小时前
谷歌SEO 内容更新焕新流程:让老页面重新起量
java·前端·javascript
老王IT1 小时前
Go开发环境搭建(window操作系统)
开发语言·后端·golang