简体   繁体   中英

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

I've tried the answers related to the question in stackoverflow . It did not work out.

Here is my project structure:

在此处输入图像描述

Controller: To render the 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. Tried using WebMvcConfigurerAdapter as well.

In browser, it displays some error like 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.

This How to disable 'X-Frame-Options' response header in Spring Security? 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. Also make sure there are no extra configuration on application.yml/properties file regarding "spring.thymeleaf.prefix".

Project Structure

try using full name with extension like index.html

I think you shouldn't return String. Try instead something like ModelAndView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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