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

启动查看效果:

图标成功显示!

相关推荐
qq_3482318513 小时前
Spring Boot开发过程中常见问题
java·spring boot·后端
程序修理员13 小时前
java+vue实现文件下载进度条
java·开发语言·vue.js
毕设源码-赖学姐13 小时前
【开题答辩全过程】以 高校教师管理系统设计与实现为例,包含答辩的问题和答案
java·eclipse
不会代码的小猴13 小时前
C++的第十一天笔记
java·前端·jvm
雨中飘荡的记忆13 小时前
Javassist实战
java
uzong13 小时前
软件工程师必须要掌握的泳道图
后端
陈文锦丫13 小时前
微服务-----
java·数据库·微服务
任子菲阳13 小时前
学Java第五十三天——IO综合练习(1)
java·开发语言·爬虫
繁华似锦respect13 小时前
单例模式出现多个单例怎么确定初始化顺序?
java·开发语言·c++·单例模式·设计模式·哈希算法·散列表