LoginSignup
0
1

More than 3 years have passed since last update.

(Intelij)Spring BootでHelloWorld

Posted at

手順

  1. InteliJで「File」→「New」→「Project」
  2. 表示されたNew Projectで「Spring Initializer」を選択し、「Next」
  3. 適当に「Group」,「Artifact」を入力。サーバにデプロイしたいので、「Packaging」は「War」を選択し、「Next」
  4. Webアプリケーションを作りたいので、「Web」→「Spring Web」にチェックし、「Next」
  5. 適当に「Project name」,「Project location」を入力し、「Fisnish」
  6. 自動作成されたDemoApplicationに以下の通り追記し、実行。

私は@RestControllerがなくて、ハマりました・・・

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+ import org.springframework.web.bind.annotation.GetMapping;
+ import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
+ @RestController
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
+    @GetMapping("/hello")
+    public String sayHello() {
+        return "Hello World";
+    }
}

  1. 以下URLにアクセスすると「Hello World」が表示されるはず

http://localhost:8080/hello

スクリーンショット 2020-07-26 12.53.06.png

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