小编bak*_*ouz的帖子

Spring Boot MVC,不返回我的视图

我对Spring Boot MVC和视图有疑问。当我进入localhost:9090时,我的页面写有“索引”,而不是像视图一样的index.html页面。你能告诉我问题是什么吗?提前致谢。

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-rest-hal-browser</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

主控制器

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

    @RequestMapping(method = RequestMethod.GET)
    public String index() {
        return "index";
    }
}
Run Code Online (Sandbox Code Playgroud)

Application.yml src /主目录/资源/application.yml

spring:
    data:
        rest:
            basePath: /api
    mvc:
        view:
            prefix: /webapp/
            suffix: .html

server:
    port: 9000
Run Code Online (Sandbox Code Playgroud)

我的index.html …

spring view maven spring-boot

2
推荐指数
2
解决办法
8991
查看次数

标签 统计

maven ×1

spring ×1

spring-boot ×1

view ×1