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

启动查看效果:

图标成功显示!

相关推荐
华仔啊16 小时前
千万别给数据库字段加默认值 null!真的会出问题
java·数据库·后端
IT_陈寒18 小时前
别再死记硬背Python语法了!这5个思维模式让你代码量减半
前端·人工智能·后端
老赵全栈实战19 小时前
【每日一技MyBatis trim标签核心用法
java·mybatis·orm
beata19 小时前
Java基础-19:Java 死锁深度解析:从原理、检测到预防与实战指南
java·前端
xyy12319 小时前
C# 读取 appsettings.json 配置指南
后端
code_YuJun20 小时前
Spring ioc 完全注解
后端
kevinzeng20 小时前
反射的初步理解
后端·面试
下次一定x20 小时前
深度解析 Kratos 客户端服务发现与负载均衡:从 Dial 入口到 gRPC 全链路落地(上篇)
后端·go
kevinzeng20 小时前
Spring 核心知识点:EnvironmentAware 接口详解
后端
xyy12320 小时前
C# / ASP.NET Core 依赖注入 (DI) 核心知识点
后端