栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot访问页面显示Whitelabel Error Page

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot访问页面显示Whitelabel Error Page

问题

新建springboot(2.5.7版本)项目配置好mvc,访问页面显示Whitelabel Error Page

项目

代码
@Controller
public class LoginController {
    @Autowired
    private LoginService loginService;

    @RequestMapping("/login")
    public String login(){
        System.out.println("访问");
        return "login";
    }
}
配置文件
server:
  port: 8080
  servlet:
    context-path: /
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
    username: root
    password: root
  mvc:
    view:
      prefix: /views/
      suffix: .html
访问登录页面

解决

配置文件添加

spring:
  resources:
    static-locations: classpath:/templates
总结

默认Springboot会从static目录加载前端静态资源,我的项目页面写在了templates目录下,通过配置static-locations参数或直接把页面放入static目录下都可以解决问题。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/584905.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号