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

启动查看效果:

图标成功显示!

相关推荐
aiopencode1 分钟前
iOS 性能监控 运行时指标与系统行为的多工具协同方案
后端
一人の梅雨2 分钟前
淘宝商品视频接口深度解析:从视频加密解密到多端视频流重构
java·开发语言·python
是喵斯特ya2 分钟前
java反序列化漏洞解析+URLDNS利用链分析
java·安全
她说..4 分钟前
MySQL数据处理(增删改)
java·开发语言·数据库·mysql·java-ee
BD_Marathon7 分钟前
【JavaWeb】ServletContext_域对象相关API
java·开发语言
E***U9458 分钟前
从新手到入门:如何判断自己是否真的学会了 Spring Boot
数据库·spring boot·后端
重生之后端学习10 分钟前
238. 除自身以外数组的乘积
java·数据结构·算法·leetcode·职场和发展·哈希算法
invicinble16 分钟前
javase-异常体系
开发语言·spring boot
yaoxin52112322 分钟前
269. Java Stream API - Map-Filter-Reduce算法模型
java·python·算法