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

启动查看效果:

图标成功显示!

相关推荐
闲人编程5 分钟前
Python协程的演进:从yield到async/await的完整历史
java·前端·python·async·yield·await·codecapsule
JCGKS18 分钟前
Go| excelize的流式迭代器
后端·golang·excel·excelize·流式读取·文件解析
帅中的小灰灰19 分钟前
C++编程建造器设计模式
java·c++·设计模式
动感小麦兜1 小时前
应用-常用工具部署命令
java·开发语言
日日行不惧千万里1 小时前
IDEA 是用什么开发的?
java·ide·intellij-idea
k***85841 小时前
SpringBoot(整合MyBatis + MyBatis-Plus + MyBatisX插件使用)
spring boot·tomcat·mybatis
q***44812 小时前
Spring Boot 中 RabbitMQ 的使用
spring boot·rabbitmq·java-rabbitmq
码事漫谈2 小时前
【C++必知必会】读取文件速记
后端
百***06012 小时前
五大消息模型介绍(RabbitMQ 详细注释版)
java·rabbitmq·java-rabbitmq
码事漫谈2 小时前
【C++必知必会】字符串操作速记
后端