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

启动查看效果:

图标成功显示!

相关推荐
BS30813_vx4 分钟前
31754+基于 Spring Boot + Vue 的网络文学交流分享平台设计与实现
vue.js·spring boot·后端
蛋先生DX6 分钟前
内存安全翻车现场的罪魁祸首,根源就在这三步里?
c++·后端·编程语言
Rain的Java大神之路11 分钟前
手写一个Spring容器
java·后端·mysql·spring·面试
小七在进步13 分钟前
C++入门(1)
java·jvm·c++
IT_陈寒15 分钟前
明明设了默认值,为什么我的JavaScript函数参数还是undefined?
前端·人工智能·后端
Wang's Blog20 分钟前
Java框架快速入门: Spring Security+OAuth2之定制登录页
java·开发语言·spring
霸道流氓气质22 分钟前
Spring AI vs Spring AI Alibaba:技术选型与平滑迁移策略
java·人工智能·spring
拽着尾巴的鱼儿27 分钟前
Idea:Cannot Run Git 无法运行git
java·git·intellij-idea
编程_大白34 分钟前
IDEA配置SQL方言
java·sql·intellij-idea
橘子汽水16837 分钟前
Leetcode 128,49最长连续序列,字母异位词分组
java·算法·leetcode