SpringBoot入門


2.MVCに基づくプログラム作成

2-3 ビューの処理(HTMLの表示)

①コントローラを以下のように修正します。indexメソッドで、Stringの"index"を返していますが これは、resources/templateフォルダの「index.html」を編集して表示するという意味です。 なお、今回は@RestControllerではなく、@Controllerを使用します。

package com.example.demo; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller; @Controller public class DemoController { @RequestMapping("/") public String index() { return "index"; } }