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

启动查看效果:

图标成功显示!

相关推荐
聆风吟º3 分钟前
【Spring Boot 报错已解决】Error creating bean with entityManagerFactory 原因分析与解决方案
java·spring boot·后端
o***74174 分钟前
SpringBoot【十一】mybatis-plus实现多数据源配置,开箱即用!
spring boot·后端·mybatis
S***84885 分钟前
【spring boot】 IDEA 启动springboot项目报missing ServletWebServerFactory
spring boot·后端·intellij-idea
Unstoppable225 分钟前
八股训练营第 34 天 | synchronized 和 Lock 的区别是什么?synchronized 和 ReentrantLock 的区别是什么?
java·八股
William_cl5 分钟前
【ASP.NET进阶】Controller 层 Action 返回值:HttpStatusCodeResult 状态码返回全解析
后端·asp.net
W***D4556 分钟前
SpringBoot + vue 管理系统
vue.js·spring boot·后端
r***934810 分钟前
【JavaEE】Spring Boot 项目创建
java·spring boot·java-ee
Ankkaya11 分钟前
小白服务器踩坑
后端
VX:Fegn089513 分钟前
计算机毕业设计|基于springboot + vue毕业设计选题管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·课程设计
matthew13 分钟前
发布对象和对象逃逸
java