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

启动查看效果:

图标成功显示!

相关推荐
心灵宝贝20 分钟前
Mac 安装 JDK 8u281(JDK-8u281-1.dmg)详细步骤(附安装包)
java·macos·intellij-idea
記億揺晃着的那天21 分钟前
从单体到微服务:如何拆分
java·微服务·ddd·devops·系统拆分
7ioik1 小时前
什么是线程池?线程池的作用?线程池的四种创建方法?
java·开发语言·spring
切糕师学AI1 小时前
Lombok 注解 @Slf4j
java·lombok
晨非辰1 小时前
数据结构排序系列指南:从O(n²)到O(n),计数排序如何实现线性时间复杂度
运维·数据结构·c++·人工智能·后端·深度学习·排序算法
寻星探路1 小时前
JavaSE重点总结后篇
java·开发语言·算法
EAIReport1 小时前
自动化报告生成产品内嵌OA/BI平台:解决传统报告痛点的技术方案
java·jvm·自动化
j***12155 小时前
Spring Boot中Tomcat配置
spring boot·tomcat·firefox
z***67775 小时前
SpringBoot(整合MyBatis + MyBatis-Plus + MyBatisX插件使用)
spring boot·tomcat·mybatis
向着光芒的女孩7 小时前
【IDEA】关不了的Proxy Authentication弹框探索过程
java·ide·intellij-idea