当前位置: 首页 > 知识库问答 >
问题:

我搜索了每一个帖子,但我无法解决我的错误

冀鸿才
2023-03-14
package com.books.bookstore.controller;

import org.springframework.stereotype.Controller;

@Controller
public class HomeController {

    @RequestMapping(value = "/")
    public String index() {
        return "index";
    }

    @RequestMapping(value = "/myAccount")
    public String myAccount() {
        return "myAccount";
    }
}

https://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.6.release com.bookstore bookstore 0.0.1-snapshot bookstore这是我的项目的描述。

<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>

http://localhost:8081/MyAccount

Wed Apr 01 14:36:39 EAT 2020出现意外错误(类型=找不到,状态=404)。无可用消息

共有1个答案

卢杰
2023-03-14

使用@GetMapping是另一个简单的解决方案

@GetMapping("/")
@ResponseBody
public String index() {
    return "index";
}
 类似资料: