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

启动查看效果:

图标成功显示!

相关推荐
间彧2 分钟前
如何处理蓝绿部署中的数据迁移和数据库版本兼容性问题?
后端
间彧6 分钟前
什么是金丝雀/灰度发布
后端
间彧15 分钟前
什么是蓝绿部署
后端
爷_40 分钟前
Golang: sqlc 和 goose 最佳实践
后端·go·全栈
听风吟丶1 小时前
MyBatis 深度实战:从基础映射到企业级性能优化
java·tomcat
仟濹1 小时前
【Java 基础】面向对象 - 继承
java·开发语言
6***83051 小时前
微服务搭建----springboot接入Nacos2.x
java
万少1 小时前
我是如何使用 Trae IDE 完成《流碧卡片》项目的完整记录
前端·后端·ai编程
ituff1 小时前
微软认证考试又免费了
后端·python·flask
倔强的石头_2 小时前
openGauss赋能智能客服:AI时代的企业服务变革
后端