【发布时间】:2018-05-31 09:38:13
【问题描述】:
我正在尝试将所有 GET 请求映射到站点的未映射 url 以显示 index.html 文件。
所以,我创建了以下@RestController:
@RequestMapping(method=RequestMethod.GET)
public String redirectToIndex() {
return "index.html";
}
我的index.html 在resources/static/index.html。我还尝试了以下控制器:
@RequestMapping(method=RequestMethod.GET)
public String redirectToIndex() {
return "/static/index.html";
}
但是,在这两种情况下,浏览器都会分别显示字符串 index.html 和 /static/index.html,而不是显示 html 文件。我在这里尝试了很多不同的其他方法来解决类似问题,但无法解决...请帮助。
编辑:
我的填@RequestController类:
@RestController
public class FeedbackController {
@Autowired
private FeedbackService feedbackService;
@RequestMapping(method=RequestMethod.POST, value="/feedback")
public Feedback addFeedback(@RequestBody Feedback feedback) {
return feedbackService.addFeedback(feedback);
}
@RequestMapping(method=RequestMethod.GET)
public String redirectToIndex() {
return "index.html";
}
}
我的pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
【问题讨论】:
-
你用的是jsps还是Thymeleaf?
-
html 的角度
标签: java html angularjs spring-boot url-mapping