forget for get

覚えるために忘れる

SpringBoot入門:環境構築

参考書はこちらを選択(Kindle Unlimitedで無料で読めるので)
Spring 解体新書

 

環境構築


IDE
Spring Tools 4 for Eclipse
https://spring.io/tools/
windows版をダウンロード、任意の場所に配置して「java -jar spring-tool-suite-xxx.jar」
sts-x.x.x.RELEASEの中のSpringToolSuite4.exeが本体

 

Pleiadesの日本語化プラグイン
https://willbrains.jp/
Pleiades プラグイン・ダウンロードからWindowsをダウンロード
解凍してsetup.exe
先ほどのSpringToolSuite4.exeを選択して日本語化

 

Lombokインストール
https://projectlombok.org/download
java -jar lombok.jar
SpringToolSuite4.exeを選択してインストール

 

Spring Tools 4の設定
コード補完の設定
ウィンドウ→設定→Java→エディタ→コンテンツアシスタント
Javaの自動有効化トリガー
.abcdefghijkemnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_
※デフォルトだと.を入力した時しか補完されない
「Enter以外の挿入トリガーを使用不可にする」にチェック

Ctrl + Shift + Fでコード整形

 

新規Springスタータープロジェクトの作成
追加ライブラリ
Spring Boot DevTools, Lombok, JDBC API, Spring Data JDBC, H2 Database, Thymeleaf, Spring Web

 

src/main/resources/templates
hello.htmlを作成

<html xmlns:th="http://www.thymeleaf.org">
    <body>
        Hello World
    </body>
</html>

 

src/main/java/com.example.demo/hello
HelloController.javaを作成

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
	@GetMapping("/hello")
	public String getHello() {
		return "hello";
	}
}

プロジェクトを右クリック→実行→SpringBootアプリケーション
http://localhost:8080/hello