java - 如何配置Spring/Spring Boot访问首页?

标签 java spring spring-boot spring-mvc thymeleaf

我正在尝试使用 Springboot(JPA、H2)和 Thymeleaf 构建我的第一个 Web 应用程序。

我的目标是通过 Controller (controllers/)获取/修改/删除存储在数据库(entities/)中的数据。

但是,家乡路线不起作用。

你能告诉我并解释一下我做错了什么吗?我忘了配置什么?

感谢您的帮助!

错误

网址:localhost:8082/

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Mar 08 14:22:21 CET 2019
There was an unexpected error (type=Not Found, status=404).
No message available

索引 Controller

@RestController
@RequestMapping("/")
public class IndexController {

    @GetMapping(value = "/")
    public ModelAndView getHome(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }
}

index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Home</title>
    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
</head>
<body>
    <p>Test</p>
</body>
</html>

文件夹

projetname/
|__src/
   |__main/
      |__java/
          |__projectname/
          |    |__controllers/
          |    |  |__IndexController.java
          |    |__entities/
          |    |__repositories/
          |    |__App.java
          |__resources/
              |__static/
              |   |__css/
              |   |__js/    
              |__templates/
              |   |__index.html 
              |__data.sql
              |__application.properties 

最佳答案

确保 spring-boot-starter-thymeleaf 包含为项目的依赖项。

this guide may help

关于java - 如何配置Spring/Spring Boot访问首页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55064267/

相关文章:

java - glassPane 没有阻止输入

java.lang.NullPointerException 错误请

Java 监控数据库的变化 - Hibernate 和 envers

java - 如何检查Grails应用程序的GORM版本

Spring @Autowired 和单例

java - kafka Avro 多个主题的消息反序列化器

oauth-2.0 - 找不到 Spring Boot OAuth 2.0 UserDetails 用户

java.lang.IllegalArgumentException : 'value' belongs to a different Realm

spring - 是否可以拆分 ehcache 配置文件?

mongodb - 使用 Grails 3.0 在数据库中存储 Spring Boot 用户