[ Spring MVC์— ๋Œ€ํ•˜์—ฌ ]

 

Spring - Spring MVC๋ฅผ ์•Œ์•„์•ผ ์‹œ์ž‘์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

์ฒ˜์Œ์—” ๋Œ€์ถฉ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•ด๋ณด๋ คํ–ˆ์ง€๋งŒ,์ด๋Ÿด์ˆ˜๊ฐ€! ์•„๋Š” ๊ฒƒ์ด ๋ฏธ์•ฝํ•˜๋‹ˆ ์‹œ์ž‘ํ•  ์ˆ˜ ์—†์—ˆ๋‹ค.๊ทธ๋ž˜์„œ ๊ฐ€์žฅ ๊ธฐ์ดˆ์ ์œผ๋กœ ์•Œ์•„์•ผํ•˜๋Š” ๊ฐœ๋…์„ ์ฐจ๊ทผ์ฐจ๊ทผ ์ •๋ฆฌํ•ด๋ณผ๊นŒ ํ•œ๋‹ค.๋‘๋‘ฅ, Spring MVC๋ž€?์•„๋งˆ ์ •๋ณด์ฒ˜

post-this.tistory.com

 

 


 

 

 

์•„์ฃผ ๊ฐ„๋‹จํ•œ ์‹ค์Šต์„ ํ•ด๋ณผ๊นŒํ•œ๋‹ค.

 

 

Hello, World ์ถœ๋ ฅํ•˜๊ธฐ
๐ŸŽƒ




1. Spring initializr ์ƒ์„ฑํ•˜๊ธฐ.

 

https://start.spring.io/

 

 

โ–ก  Dependencies - SpringWeb ์„ ํƒํ•˜๊ธฐ.

โ–ก  Java ํ•ด๋‹นํ•˜๋Š” ๋ฒ„์ „์— ์„ ํƒํ•˜๊ธฐ.

 

 

 

 

โœ”๏ธŽ  [Mac ๊ธฐ์ค€] ์ž๋ฐ” ๋ฒ„์ „์„ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค๋ฉด?

 

  • ํ„ฐ๋ฏธ๋„์— ๋“ค์–ด๊ฐ„๋‹ค.
  • ํ„ฐ๋ฏธ๋„์— java --version ์ด๋ผ๊ณ  ์น˜๋ฉด๋œ๋‹ค.
    โ–ธ openjdk 17.0.11์œผ๋กœ ํ™•์ธ๋๋‹ค.
  • ๋งŒ์•ฝ ์•ˆ๋œฌ๋‹ค๋ฉด java ์„ค์น˜๊ฐ€ ์•ˆ๋˜์–ด์žˆ์œผ๋‹ˆ, ์„ค์น˜ํ•ฉ์‹œ๋‹ค!

 

 


 

 

 

 

2. GENERATE ๋ˆŒ๋Ÿฌ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

 

โ–ก ํ•˜๋‹จ ๋งจ ์™ผ์ชฝ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๋œ๋‹ค.

 

 

 

 


 

 

 

 

3. ์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ IntelliJ๋กœ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ.

 

โ–ก Open์„ ๋ˆŒ๋Ÿฌ์ฃผ๊ธฐ.

 

โ–ก ์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ๊ฐ€ ์žˆ๋Š” ๊ณณ์„ ์ฐพ๋Š”๋‹ค.
โ–ก build.gradle์„ ์„ ํƒํ•˜์—ฌ ์—ด์–ด์ค€๋‹ค.

 

 

 

โ–ก Open as Project๋ฅผ ์„ ํƒํ•˜์—ฌ ์—ด์–ด์ค€๋‹ค.

 

 

 

 

 


 

 

 

 

4. HelloController๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.

 

 [ ์ปจํŠธ๋กค๋Ÿฌ ๋งŒ๋“œ๋Š” ์ด์œ ์— ๋Œ€ํ•ด์„œ ]

 

-

 

โ–ก com.pratice.HelloWorld์— ๋งˆ์šฐ์Šค ์™ผ์ชฝ์„ ํด๋ฆญํ•œ๋‹ค.

 

 

โ–ก Class - HelloController๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.

 

 

โ–ก  HelloController๋ฅผ ์ƒ์„ฑํ–ˆ๋‹ค.

 

 

 

 


 

 

 

 

5. HelloController์— HelloWorld๊ฐ€ ์ถœ๋ ฅ๋˜๋„๋ก ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ.

 

@RestController
public class HelloController {

    @GetMapping("")
    public String helloWorld() {
        return "Hello, World";
    }

}

 

@RestController

:  ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•˜์ž๋ฉด, Hello, World๋ผ๋Š” ๋ฌธ์žฅ์ด ์›น์‚ฌ์ดํŠธ์— ์ถœ๋ ฅ๋˜๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด(JSON์œผ๋กœ) ์–ด๋…ธํ…Œ์ด์…˜(@)์„ ์ ์–ด์ค€๋‹ค.

 

@GetMapping("")

: ์„œ๋ฒ„์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ์กฐํšŒํ•  ๋•Œ ์‚ฌ์šฉ, ("")์— ์š”์ฒญ ๋ฐ›์„ URL์„ ์ ๋Š”๋‹ค. ํ˜„์žฌ ์ ํ˜€์žˆ์ง€ ์•Š์œผ๋‹ˆ localhost:8080์ด ๋œ๋‹ค.

 

 

 

 

[ @RestController ์„ค๋ช… ]

 

Spring - @Controller์™€ @RestController ๊ทธ๋ฆฌ๊ณ  ์ƒํƒœ์ฝ”๋“œ

[ SpringMVC์— ๋Œ€ํ•˜์—ฌ ] Spring - Spring MVC๋ฅผ ์•Œ์•„์•ผ ์‹œ์ž‘์ด ๊ฐ€๋Šฅํ•˜๋‹ค.์ฒ˜์Œ์—” ๋Œ€์ถฉ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•ด๋ณด๋ คํ–ˆ์ง€๋งŒ,์ด๋Ÿด์ˆ˜๊ฐ€! ์•„๋Š” ๊ฒƒ์ด ๋ฏธ์•ฝํ•˜๋‹ˆ ์‹œ์ž‘ํ•  ์ˆ˜ ์—†์—ˆ๋‹ค.๊ทธ๋ž˜์„œ ๊ฐ€์žฅ ๊ธฐ์ดˆ์ ์œผ๋กœ ์•Œ์•„์•ผํ•˜๋Š”

post-this.tistory.com

 

 

 

[ @GetMapping ์„ค๋ช… ]

 

SpringBoot - GET๊ณผ POST ๊ทธ๋ฆฌ๊ณ  @GetMapping

[ @Controller์™€ @RestController ] Spring - @Controller์™€ @RestController ๊ทธ๋ฆฌ๊ณ  ์ƒํƒœ์ฝ”๋“œ[ SpringMVC์— ๋Œ€ํ•˜์—ฌ ] Spring - Spring MVC๋ฅผ ์•Œ์•„์•ผ ์‹œ์ž‘์ด ๊ฐ€๋Šฅํ•˜๋‹ค.์ฒ˜์Œ์—” ๋Œ€์ถฉ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•ด๋ณด๋ คํ–ˆ์ง€๋งŒ,์ด๋Ÿด์ˆ˜๊ฐ€!

post-this.tistory.com

 

 

 


 

 

 

 

6. localhost:8080, ๊ฒฐ๊ณผ ๋ณด๊ธฐ.

 

๐Ÿชฝ

"ํ‹€๋ฆฐ ๋‚ด์šฉ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."

 

 

 

[ ๋ธ”๋กœ๊ทธ์— ์“ด ๋‚ด์šฉ๋“ค์˜ ์ถœ์ฒ˜๋Š” ์•„๋ž˜์— ์ ์–ด๋‘˜ํ…Œ๋‹ˆ

๋“ค์–ด๊ฐ€์„œ ์ฝ์–ด๋ณด์‹œ๋ฉด ๋”์šฑ ๋„์›€์ด ๋˜์‹ค ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค ]

 

 

 


 

 

- Hello World ์ถœ์ฒ˜

 

์Šคํ”„๋ง๋ถ€ํŠธ๋Š” ์ฒ˜์Œ์ด๋ผ #1 "Hello, world" ๋ฅผ ์ถœ๋ ฅํ•˜๊ธฐ๊นŒ์ง€

Hello, world

velog.io

 

 

- GetMapping ์ถœ์ฒ˜

 

[spring] @Controller์™€ @GetMapping

์ด๋ฒˆ์—๋Š” mapping์„ ํ†ตํ•ด์„œ ๊ฐ„๋‹จํ•œ html ํŽ˜์ด์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ฒ˜๋ฆฌ ๊ณผ์ • ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ณผ์ •์€ ๋‹ค์Œ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ๋งคํ•‘์„ ํ†ตํ•ด Controller๊ฐ€ ํŠน์ • View

coding-nyan.tistory.com

 

 

- RestController ์ถœ์ฒ˜

 

3.2. RestController ์‚ฌ์šฉํ•˜๊ธฐ · SpringBoot

 

dorothy-koo.gitbooks.io

 

+ Recent posts