GET
リクエストをマップされていないURLにマップして、index.html
ファイルを表示しようとしています。SpringブートでAngular2 Single PageのアプリケーションのHTMLファイルではなく文字列が表示される
@RequestMapping(method=RequestMethod.GET)
public String redirectToIndex() {
return "index.html";
}
マイindex.html
resources/static/index.html
である:
だから、私は@RestController
次のように作成しました。
@RequestMapping(method=RequestMethod.GET)
public String redirectToIndex() {
return "/static/index.html";
}
しかしながら、両方の場合に、ブラウザーは文字通りストリングindex.html
と/static/index.html
それぞれの代わりに、HTMLファイルを示す例を示します。私は、次のコントローラを試みました。私はここで同様の質問に別のアプローチをたくさん試しましたが、解決することができません...助けてください。
EDIT:
マイ塗りつぶし@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
:@RestController注釈ResponseBodyで
<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のための角度 – swdon