Spring/SpringBoot

Spring Boot으로 웹 출시까지

느리지만 꾸준하게 2022. 5. 30. 10:58

여기서 프로젝트를 시작해보자.

 

Spring setting

 

 

 

 

 

 

그리고 Building Restful Web Service 사이트에서 튜토리얼을 진행 해준다.

 

Greeting Class

package com.godcoder.myrest;

public class Greeting {

    private final long id;
    private final String content;

    public Greeting(long id, String content) {
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }

    public String getContent() {
        return content;
    }
}

 

GreetingController Class

package com.godcoder.myrest;

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @GetMapping("/greeting")
    public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
        return new Greeting(counter.incrementAndGet(), String.format(template, name));
    }
}

 

 

 

MyresetApplication 돌려주고

http://localhost:8080/greeting 로 들어가본다.

http://localhost:8080/greeting?name=User 여기로도 들어가본다.

package com.godcoder.myrest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyrestApplication {
	public static void main(String[] args) {
		SpringApplication.run(MyrestApplication.class, args);
	}
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<코딩의 신 - Spring Boot으로 웹 출시까지 #1. 환경 설정>

참고: https://www.youtube.com/watch?v=FYkn9KOfkx0&list=PLPtc9qD1979DG675XufGs0-gBeb2mrona&index=1