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

启动查看效果:

图标成功显示!

相关推荐
Victor3564 分钟前
Redis(78) 如何设置Redis的缓存失效策略?
后端
开心-开心急了5 分钟前
Flask入门教程——李辉 第四章 静态文件 关键知识梳理 更新1次
后端·python·flask
稻草猫.5 分钟前
Java网络编程套接字
java·后端·java-ee·idea
Victor3567 分钟前
Redis(79)Redis的缓存穿透是什么?
后端
绝无仅有9 分钟前
猿辅导Java面试真实经历与深度总结(三)
后端·面试·github
绝无仅有10 分钟前
猿辅导MySQL面试常见问题解析(一)
后端·面试·github
云泽8082 小时前
函数模板与类模板:C++泛型编程核心解析
java·开发语言·c++
缺点内向6 小时前
Java:创建、读取或更新 Excel 文档
java·excel
带刺的坐椅6 小时前
Solon v3.4.7, v3.5.6, v3.6.1 发布(国产优秀应用开发框架)
java·spring·solon
四谎真好看8 小时前
Java 黑马程序员学习笔记(进阶篇18)
java·笔记·学习·学习笔记