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

启动查看效果:

图标成功显示!

相关推荐
苏三说技术4 分钟前
推荐几个牛逼的AI Agent项目
后端
polaris06305 分钟前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
卓怡学长20 分钟前
m280本科生导师指导平台
java·数据库·spring·tomcat·maven·intellij-idea
武子康22 分钟前
大数据-253 离线数仓 - Airflow 入门与任务调度实战:DAG、Operator、Executor 部署排错指南
大数据·后端·apache hive
一直都在57241 分钟前
Java死锁
java·开发语言
IT_陈寒1 小时前
深入理解JavaScript:核心原理与最佳实践
前端·人工智能·后端
树獭叔叔1 小时前
GRPO:比PPO更简单的RLHF算法
后端·aigc·openai
shelter1 小时前
并发操作session对象导致登录闪退问题
后端
兆子龙1 小时前
TypeScript高级类型编程:从入门到精通
前端·后端
IT_陈寒1 小时前
Python开发者的效率革命:这5个技巧让你的代码提速50%!
前端·人工智能·后端