进阶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 分钟前
多级缓存设计思路——本地 + 远程的一致性策略、失效风暴与旁路缓存的取舍
后端
悟能不能悟16 分钟前
java 设置日期返回格式的几种方式
java·开发语言
爱笑的眼睛1118 分钟前
深入解析PyTorch nn模块:超越基础模型构建的高级技巧与实践
java·人工智能·python·ai
Smile_25422041820 分钟前
解决本地 Windows 开发机无法注册到 PowerJob 服务器的问题
java·tcp/ip
float_六七22 分钟前
Spring AOP连接点实战解析
java·后端·spring
武子康33 分钟前
大数据-183 Elasticsearch - 并发冲突与乐观锁、分布式数据一致性剖析
大数据·后端·elasticsearch
while(1){yan}38 分钟前
基于IO流的三个小程序
java·开发语言·青少年编程
CoderYanger1 小时前
贪心算法:7.最长连续递增序列
java·算法·leetcode·贪心算法·1024程序员节
期待のcode1 小时前
MyBatis-Plus的Wrapper核心体系
java·数据库·spring boot·后端·mybatis
曼巴UE51 小时前
UE C++ 字符串的操作
java·开发语言·c++