[Spring Boot2.4.2] プロジェクト作成

Test1.java

1
2
3
4
5
6
7
8
9
10
11
12
13
package com.example.demo;
 
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
public class Test1 {
     
    @GetMapping("/test1")
    public String write1() {
        return "Hello World1";
    }
}

RestControllerはメソッドの戻り値を画面に表示する
@GetMappingは@RequestMapping(method=RequestMethod.GET)と同じ意味
Run As -> Spring boot
http://localhost:8080/test1
Hello World1

application.properties

1
server.port=8756

pom.xml

1
2
3
4
5
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>true</scope>
</dependency>

spring-boot-devtoolsをtrueにするとファイルを更新した際に、アプリを再起動しなくても更新される。