启动了Spring boot之后,浏览器访问http://localhost:8080/出错

问题遇到的现象和发生背景

启动了Spring boot之后,浏览器访问http://localhost:8080/出错

img

操作环境、软件版本等信息

这是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.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring_demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring_demo</name>
    <description>spring_demo</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

这是主类SpringDemoApplication.java

package com.example.spring_demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = "com.example")
public class SpringDemoApplication {
public static void main(String[] args) {
    SpringApplication.run(SpringDemoApplication.class, args);
}
}

这是helloController.java

package com.example.spring_demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author mhw
 * @create 2023/6/5 9:58
 * @email 480738950@qq.com
 */
@Controller
public class helloController {
    @RequestMapping("/index")
    public String sayHello(){
        return "index";
    }
}
尝试过的解决方法

img


这是整个目录结构

我想要达到的结果

我想要在浏览器访问到index页面

http://localhost:8080/index 加上资源路径index试一下.

你controller中的请求路径是 /index,所以你在浏览器请求的时候也应该加上 /index,也就是 http://localhost:8080/index