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

启动查看效果:

图标成功显示!

相关推荐
共享家95276 分钟前
Java入门(类和对象)
java·开发语言
智_永无止境10 分钟前
Spring Boot 动态多数据源:核心思路与关键考量
spring boot
Arya_aa11 分钟前
Java中的static
java
北城笑笑16 分钟前
Vue 100 ,Metaspace memory lack Error( 元空间内存不足 )
java·前端·javascript·vue
掘金者阿豪20 分钟前
小爱音箱秒变智能搭子!MiGPT GUI+cpolar,远程操控超省心
后端
Han.miracle22 分钟前
Spring IoC 与 DI 核心知识点综合测试题
java·前端·数据库
婉然从物24 分钟前
IDEA中plugins无法连接网络
java·ide·intellij-idea
xiaogai_gai24 分钟前
ETL数据流程实战:轻易云平台整合金蝶云星空API接口
java·数据仓库·etl
Java编程爱好者31 分钟前
Java面试高频场景题:在工作中或者一些组件源码里面或多或少会用到锁,你能整理概括下锁的分类么?
后端
sheji341632 分钟前
【开题答辩全过程】以 基于springboot的健身预约系统的设计与实现为例,包含答辩的问题和答案
java·spring boot·后端