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

启动查看效果:

图标成功显示!

相关推荐
BigTopOne1 小时前
02 use:引入路径
后端
BigTopOne1 小时前
09 match 与 if let:模式匹配
后端
BigTopOne1 小时前
4. 容易误解的地方:`pub` 不一定真的公开
后端
BigTopOne1 小时前
06 trait:定义行为约定
后端
BigTopOne1 小时前
01 mod:声明模块
后端
BigTopOne1 小时前
03 mod 和 use 怎么选
后端
BigTopOne1 小时前
08 Result 与 Option:代替 null 和异常
后端
BigTopOne1 小时前
07-Box 与 Arc:智能指针
后端
BigTopOne1 小时前
05 impl:给类型写方法
后端
木雷坞2 小时前
n8n Docker 读不到 CSV,先分清宿主机目录和容器路径
java·docker·容器