1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Spring BootプロジェクトをVSCodeでいい感じに設定する

Posted at

はじめに

やること

  • VSCodeでSpring Bootを含んだJavaプロジェクトを作る

環境

  • Java 17
  • Spring Boot 3.0.6
  • Gradle

手順

Spring Boot Extension Packをインストールする。
image.png

CTRL+Shift+Pで検索欄を開き、Spring Initializr: Create a Gradle Projectを押下。
image.png

バージョンを選択。
image.png

言語はJavaを選択。
image.png

グループIDを入力。com.<userID>とかでいいと思います。
image.png

プロジェクト名を入力。なんでもいいと思います。
image.png

パッケージタイプはJarを選択。
image.png

Javaバージョンは17を選択。
image.png

依存関係を選択。
Webを構築したい場合はSpring WebThymeleafを選択しとけばよいと思います。他はプロジェクトに合わせて。
image.png

最後に、プロジェクトを作成するフォルダの場所を指定。
image.png
右下にSuccessfullyが出たらOK。
これでプロジェクトは完成です。

実行する

example/controllerHelloController.javaを、resources/templateshello.htmlを作成する。
内容は以下の通り。

HelloController.java
package com.example.springbootdemo.controller;

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

@Controller
public class HelloController {
    @RequestMapping("/hello")
    public String index() {
        return "hello";
    }
}
hello.html
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Hello!</title>
    </head>
    <body>
        <h1>Hello!</h1>
    </body>
</html>

実行する際は、「実行>デバッグの開始」を押す。
一度目はうまくいかない場合があるので注意。その際はもう一度実行しなおす。

http://localhost:8080/helloにアクセスしてみて、以下のような表示が出れば成功。
image.png

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?