进阶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学习30
java·开发语言·学习
次元工程师!3 分钟前
LangFlow开发(三)—Bundles组件架构设计(3W+字详细讲解)
java·前端·python·低代码·langflow
oddsand12 小时前
Redis网络模型
java·数据库·redis
皮卡祺q2 小时前
【redies0-导论】分布式系统的演进-引进redis原因
java·数据库·redis
roman_日积跬步-终至千里2 小时前
如何分析复杂架构:一套真正能落地的方法
java·开发语言·架构
geovindu2 小时前
go: Semaphore Pattern
开发语言·后端·设计模式·golang·企业级信号量模式
IT_陈寒2 小时前
Redis内存用爆了,原来我们都忽略了这个配置
前端·人工智能·后端
武子康2 小时前
Java-02 深入浅出MyBatis 3 快速入门:环境配置、项目创建与 CRUD 操作
java·后端
Don.TIk2 小时前
ChapterOne-搭建项目骨架
java·spring·spring cloud·mybatis
Don.TIk2 小时前
ChaperTwo-整合 SaToken 实现 JWT 登录功能
java·开发语言