java—“循环视图路径将分派回当前处理程序url”当使用spring引导和thymeleaf时

2w3kk1z5  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(345)

当使用spring boot和thymeleaf时,当尝试访问/home url时,我得到以下结果:
servletexception:循环视图路径[home]:将再次分派回当前处理程序url[/home]。检查viewresolver设置(提示:这可能是由于生成默认视图名而导致的未指定视图。)
pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.demo</groupId>
    <artifactId>watchlist</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>watchlist</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

main/java/com.demo.watchlistapplication.java:

package com.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WatchlistApplication {

    public static void main(String[] args) {
        SpringApplication.run(WatchlistApplication.class, args);
    }

}

main/java/com.demo.controller.homecontroller.java:

package com.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HomeController {

    @GetMapping("/home")
    public ModelAndView home() {

        return new ModelAndView("home");
    }
}

main/resources/templates/home.html:

<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="viewport" content="width = device-width, initial-scale = 1, shrink-to-fit = no">
    <title>Web app</title>
</head>

<body>

<p th:text="'Hello world'"></p>

</body>
</html>
von4xj4u

von4xj4u1#

用注解@restcontroller而不是@controller注解控制器类“homecontroller”。
似乎重复的循环视图路径错误 Spring 启动

相关问题