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

启动查看效果:

图标成功显示!

相关推荐
JIngJaneIL4 分钟前
汽车租赁|汽车管理|基于Java+vue的汽车租赁系统(源码+数据库+文档)
java·vue.js·spring boot·汽车·论文·毕设·汽车租赁
曾经的三心草13 分钟前
JavaEE初阶-多线程1
android·java·java-ee
m***567216 分钟前
【Spring】Spring MVC案例
java·spring·mvc
努力发光的程序员27 分钟前
互联网大厂Java面试:从Spring Boot到微服务架构的技术问答
spring boot·kafka·microservices·java interview·message queue·technical q&a
Geoking.1 小时前
【Java】Java Stream 中的 collect() 方法详解:流最终操作的核心工具
java·开发语言
canonical_entropy1 小时前
可逆计算的方法论来源
后端·低代码
数据知道1 小时前
【Flask】一文掌握 Flask 基础用法
数据库·后端·python·flask·python web
清风徐来QCQ1 小时前
javaScript(map,ref,?,forEach,watch)
java·前端·javascript
q***73551 小时前
windows配置永久路由
android·前端·后端
7***n751 小时前
Java构建工具
java·开发语言