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

启动查看效果:

图标成功显示!

相关推荐
WiChP1 小时前
【V0.1B5】从零开始的2D游戏引擎开发之路
java·服务器·数据库
cch89181 小时前
汇编与Java:底层与高层的编程对决
java·开发语言·汇编
荒川之神2 小时前
拉链表概念与基本设计
java·开发语言·数据库
cch89182 小时前
汇编与Go:底层到高层的编程差异
java·汇编·golang
chushiyunen3 小时前
python中的@Property和@Setter
java·开发语言·python
禾小西3 小时前
Java中使用正则表达式核心解析
java·python·正则表达式
2401_895521343 小时前
SpringBoot Maven快速上手
spring boot·后端·maven
yoyo_zzm3 小时前
JAVA (Springboot) i18n国际化语言配置
java·spring boot·python
APIshop3 小时前
Java获取京东商品详情接口(item_get)实战指南
java·linux·数据库