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

启动查看效果:

图标成功显示!

相关推荐
_MyFavorite_16 小时前
JAVA重点基础、进阶知识及易错点总结(8)List 接口(ArrayList、LinkedList、Vector)
java·开发语言·list
第二层皮-合肥16 小时前
基于C#的工业测控软件-依赖库
java·开发语言
Carsene16 小时前
开源项目文档架构设计:Git Submodule 实现文档与代码的优雅分离
前端·后端
吾诺16 小时前
Spring Boot 整合 Redis 步骤详解
spring boot·redis·bootstrap
openallzzz16 小时前
【面经分享】Java实习
java·开发语言
indexsunny16 小时前
互联网大厂Java面试:从Spring Boot到微服务的逐步挑战
java·数据库·spring boot·redis·微服务·面试·电商
276695829216 小时前
租车帮(悟空)订单查询算法分析
java·服务器·前端·悟空·悟空app·租车帮·租车帮逆向
用户83562907805116 小时前
Python 实现 Word 文档图片插入与排版技巧
后端·python
鬼蛟16 小时前
Spring Boot
java·开发语言
AI茶水间管理员17 小时前
部署70B大模型到底要多大显存?一文算清所有账
人工智能·后端