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

启动查看效果:

图标成功显示!

相关推荐
于先生吖21 分钟前
Java框架开发短剧漫剧系统:后台管理与接口开发
java·开发语言
Victor3561 小时前
MongoDB(51)什么是分片?
后端
Victor3561 小时前
MongoDB(50)副本集中的角色有哪些?
后端
daidaidaiyu1 小时前
Spring IOC 源码学习 声明式事务的入口点
java·spring
myloveasuka1 小时前
[Java]查找算法&排序算法
java·算法·排序算法
清水白石0081 小时前
Free-Threaded Python 实战指南:机遇、风险与 PoC 验证方案
java·python·算法
发际线还在2 小时前
互联网大厂Java三轮面试全流程实战问答与解析
java·数据库·分布式·面试·并发·系统设计·大厂
IT_陈寒2 小时前
JavaScript开发者必看:5个让你的代码性能翻倍的隐藏技巧
前端·人工智能·后端
shengjk12 小时前
大数据工程师必看:为什么你的 IN 查询在 Flink/Spark 上慢到离谱?
后端
武子康2 小时前
大数据-252 离线数仓 - Airflow + Crontab 入门实战:定时调度、DAG 编排与常见报错排查
大数据·后端·apache hive