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

启动查看效果:

图标成功显示!

相关推荐
北冥you鱼28 分钟前
Go-Ethereum (Geth) 最佳实践:从部署到生产环境优化
开发语言·后端·golang
thefool11226635 分钟前
Java 方法重载
java
程序员爱钓鱼2 小时前
Rust 函数与返回值详解:参数、表达式与返回类型
后端·rust
这不小天嘛7 小时前
JAVA八股——J集合篇
java·开发语言
什巳10 小时前
JAVA练习278- 和为 K 的子数组
java·学习·算法·leetcode
豆瓣鸡10 小时前
RocketMQ学习-Spring Boot消息实践
java·spring boot·rocketmq
wuqingshun31415910 小时前
说一下mysql的覆盖索引
java
罗超驿11 小时前
2.算法效率的核心密码:时间复杂度和空间复杂度详解
java·数据结构·算法
栈溢出了12 小时前
Redis 分片集群与哈希槽笔记
java·redis·笔记·spring
这里是杨杨吖12 小时前
SpringBoot+Vue心理健康咨询系统 附带详细运行指导视频
spring boot·vue·心理健康