要在 Spring Boot 中配置 wwwroot 静态文件目录并默认打开 wwwroot 下的 index.html 文件,可以按照以下步骤进行操作:

  1. 在 Spring Boot 配置文件中加入以下配置:
<mvc:resources mapping='/static/**' location='/wwwroot/'/>
<mvc:view-controller path='/' view-name='forward:index.html'/>

这里使用了 mvc:resources 标签来指定静态资源的映射路径和实际存放路径,同时使用了 mvc:view-controller 标签来指定访问根路径 '/' 时要跳转到的视图名称 'index.html'。

  1. 在 wwwroot 目录下创建 index.html 文件,并填充内容。

  2. 启动 Spring 应用程序,访问 http://localhost:8080/ 即可看到 index.html 文件的内容。

Spring Boot 配置 wwwroot 静态文件目录并默认打开 index.html

原文地址: https://www.cveoy.top/t/topic/oILv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录