LoginSignup
1
1

More than 1 year has passed since last update.

VSCodeでSpringboot+Thymeleafアプリを1から作成(環境構築編)

Posted at

概要

  • 本題の通り。SEをやっていながら直近はShellやサーバ構築などに携わり、Javaなどの開発案件に久しく関わっていなかった。かつ新規開発案件はほぼ初。
  • 頑張ったね私、という自分への鼓舞が主な目的

環境

  • JDK17.0.2
  • Springboot 2.6.6
  • Gradle

VSCodeでSpringboot環境を構築

VSCodeインストール

拡張機能ダウンロード

  • VSCodeくんにまずは必要最低限の拡張機能をダウンロードしてあげましょう。
  • これによりVSCodeが「Javaいけます」「Springboot使えます」といった優秀な部下に大変身します。
    • Java Extension Pack
    • Spring Boot Extension Pack
    • Lombok Annotations Support for VS Code

プロジェクト作成

  • コマンドパレットに「Spring」を入力
  • Spring Initializr: Generate a Gradle Projectを選択
  • バージョンを選択(最新がいい場合は公式サイトhttps://spring.io/projects/spring-boot をみてバージョン確認するといいです)
  • Javaを選択
  • パッケージ名を入力
  • プロジェクト名を入力
  • 依存関係の選択
    • Spring Web
    • Thymeleaf
    • Lombok
  • プロジェクト保存先の指定
    VSCodeの右下に「Successfully generated」と表示されていれば作成完了です!やったあ!

Hello Worldを表示

ディレクトリ、ファイルの作成

  • 作成したプロジェクト配下にcontrollerディレクトリを作成します
  • controllerディレクトリ内に「HelloController.java」を作成します
  • 以下のように内容を修正してみましょう。
HelloController.java
// パッケージ名は作成したときのものに合わせてね
package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {
    @RequestMapping("/hello")
	public String index() {
		return "hello";
	}
}
  • src/main/resources/templates/内にhello.htmlを作成します。
hello.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Hello!!!</title>
</head>
<body>
    <h1>HelloWorld</h1>
</body>
</html>

いざ実行

まとめ

  • とりあえず、環境構築→プロジェクト作成→Hello World表示までの導入部分を今回は記事にしてみました。
  • 現在進行系で開発を進めているので、空いた時間で次の段階についてまとめていきたいと思います。
  • 今回Thymeleafは全くと言っていいほど登場していませんが、今後大活躍するから・・・・してるから・・・
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1