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

启动查看效果:

图标成功显示!

相关推荐
我命由我123454 分钟前
Android 开发 Room 数据库升级问题:A migration from 6 to 7 was required but not found.
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
kiss strong5 分钟前
springboot替换word模板&加入二维码&加水印&转为pdf
spring boot·后端·pdf
黄筱筱筱筱筱筱筱5 分钟前
7.适合新手小白学习Python的异常处理(Exception)
java·前端·数据库·python
QQ17958063966 分钟前
基于springboot+vue的hive的歌曲音乐筛选推荐系统网站(源码+lw+部署文档+讲解等)
vue.js·hive·spring boot
Stecurry_308 分钟前
Springboot整合SpringMVC --从0到1
java·spring boot·后端
Serene_Dream8 分钟前
NIO 的底层机理
java·jvm·nio·mmap
skywalker_1112 分钟前
多线程&JUC
java·开发语言·jvm·线程池
黎雁·泠崖13 分钟前
Java基础核心能力总结:从语法到API的完整知识体系
java·开发语言
JaguarJack18 分钟前
PHP 现在可以零成本构建原生 iOS 和 Android 应用 NativePHP for Mobile v3 发布
后端·php·laravel·服务端
_周游20 分钟前
Java8 API 文档搜索引擎_2.索引模块(实现细节)
java·搜索引擎·intellij-idea