简体   繁体   English

Spring 启动 - 未呈现登陆 (index.html) 页面?

[英]Spring boot - Not rendering the landing(index.html) page?

I've tried the answers related to the question in stackoverflow .我已经尝试了与 stackoverflow 中的问题相关的答案 It did not work out.它没有成功。

Here is my project structure:这是我的项目结构:

在此处输入图像描述

Controller: To render the index.html Controller:渲染index.html

@Controller
public class MainController {

    @RequestMapping(value="/",method = RequestMethod.GET)
    public String homepage(){
        System.out.println("Inside controller..");
        return "index";
    }
}

When i'm trying to hit the URL , it prints Inside controller.. but not rendering the index page.当我尝试点击URL时,它会打印Inside controller..但不会呈现index页。 Tried using WebMvcConfigurerAdapter as well.也尝试使用WebMvcConfigurerAdapter

In browser, it displays some error like Whitelabel Error Page在浏览器中,它显示一些错误,如Whitelabel Error Page

Am I missing something out here?我在这里错过了什么吗?

Check for errors in the browser console.检查浏览器控制台中的错误。 'X-Frame-Options' may be set to 'DENY' that may block html page to load in the browser. 'X-Frame-Options' 可以设置为 'DENY',这可能会阻止 html 页面加载到浏览器中。

This How to disable 'X-Frame-Options' response header in Spring Security? 如何在 Spring Security 中禁用“X-Frame-Options”响应标头? may help.可能有帮助。

Please check your project structure.请检查您的项目结构。 Application, and other packages like model, controller etc. should be under the same package or on the same level.应用程序和其他包如 model、controller 等应该在同一个 package 下或在同一级别。 Also make sure there are no extra configuration on application.yml/properties file regarding "spring.thymeleaf.prefix".还要确保在 application.yml/properties 文件中没有关于“spring.thymeleaf.prefix”的额外配置。

Project Structure项目结构

try using full name with extension like index.html尝试使用带扩展名的全名,如 index.html

I think you shouldn't return String.我认为你不应该返回字符串。 Try instead something like ModelAndView .试试像ModelAndView这样的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM