ํฐ์คํ ๋ฆฌ ๋ทฐ
Hello Controller ํ ์คํธ ์ฝ๋ ์์ฑํ๊ธฐ
ํจํค์ง์ ํด๋์ค๋ฅผ ์์ฑํ๋ค. (์ผ๋ฐ์ ์ธ ํจํค์ง๋ช ์ ์น ์ฌ์ดํธ ์ฃผ์์ ์ญ์์ผ๋ก ์์ฑ ) ์ฝ๋๋ฅผ ์์ฑํด์ผํ๋๋ฐ import๋ฅผ ์ณ๋ ์๊พธ ์ง์์ ธ์ ๋๋ฌด๋ ๋นํฉํ๋ค. ์ธํ ๋ฆฌ์ ์ด๋ฅผ ์์จ๋ดค์ผ๋ ๋ชจ๋ฅด์ง.. ์ฌ์ฉํ์ง ์๋ import๋ ์๋์ผ๋ก ์ง์์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ด์ ๊ทธ๋ฐ๊ฑฐ์๋ค ๊ทธ๋ฅ import๋ง๊ณ ์ฝ๋๋ฅผ ์์ฑํ๋ฉด ๋๋๊ฑฐ์๋ค; ์ข๊ตฐ
//Application ํด๋์ค๋ ์์ผ๋ก ๋ง๋ค ํ๋ก์ ํธ์ ๋ฉ์ธ ํด๋์ค๊ฐ ๋๋ค.
package com.yeahajeong.hastagram;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//@SpringBootApplication์ผ๋ก ์ธํด ์คํ๋ง ๋ถํธ์ ์๋์ค์ , ์คํ๋ง Bean์ฝ๊ธฐ์ ์์ฑ์ ๋ชจ๋ ์๋์ผ๋ก ์ค์ ํ๋ค.
//ํนํ๋ @SpringBootApplication์ด ์๋ ์์น๋ถํฐ ์ค์ ์ ์ผ๊ฑฐ๊ฐ๊ธฐ ๋๋ฌธ์ ์ด ํด๋์ค๋ ํญ์ ํ๋ก์ ํธ ์๋จ์ ์์ฑํ์ผํจ
@SpringBootApplication
public class Application {
public static void main(String[] args) {
//SpringApplication.run ์ผ๋ก ์ธํด ๋ด์ฅ WAS(์น ์ ํ๋ฆฌ์ผ์ด์
์๋ฒ)๋ฅผ ์คํ
//๋ด์ฅ WAS๋ ๋ณ๋๋ก ์ธ๋ถ์ WAS๋ฅผ ๋์ง ์๊ณ ์ ํ๋ฆฌ์ผ์ด์
์ ์คํํ ๋ ๋ด๋ถ์์ WAS๋ฅผ ์คํํ๋ ๊ฒ
SpringApplication.run(Application.class, args);
//์ด๋ ๊ฒ ํ๋ฉด ํญ์ ์๋ฒ์ ํฐ์บฃ์ ์ค์นํ ํ์๊ฐ ์๊ณ ์คํ๋ง ๋ถํธ๋ก ๋ง๋ค์ด์ง Jarํ์ผ๋ก ์คํํ๋ฉด ๋จ
}
}
์คํ๋ง ๋ถํธ์์๋ ์ธ์ ์ด๋์๋ ๊ฐ์ ํ๊ฒฝ์์ ์คํ๋ง ๋ถํธ๋ฅผ ๋ฐฐํฌํ ์ ์๊ธฐ ๋๋ฌธ์ ๋ด์ฅ AWS์ฌ์ฉ์ ๊ถ์ฅํ๊ณ ์๋ค. ์ธ์ฅ WAS๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ฉด ๋ชจ๋ ์๋ฒ๋ WAS์ ์ข ๋ฅ์ ๋ฒ์ , ์ค์ ์ ์ผ์น์์ผ์ผํ๋๊น ๋ฒ๊ฑฐ๋กญ๋ค.
ํ ์คํธ๋ฅผ ์ํ Controller ์์ฑํ ํ ๊ฐ๋จํ API๋ฅผ ๋ง๋ค์ด๋ณธ๋ค.
package com.yeahajeong.hastagram.web;
import org.springframework.web.bind.annotation.RestController;
//@RestController
//์ปจํธ๋กค๋ฌ๋ฅผ JSON์ ๋ฐํํ๋ ์ปจํธ๋กค๋ฌ๋ก ๋ง๋ค์ด์ค
//์์ ์๋ @RequestBody๋ฅผ ๊ฐ ๋ฉ์๋๋ง๋ค ์ ์ธํ๋๊ฒ์ ํ๋ฒ์ ํด์ฃผ๋ ๊ฒ
@RestController
public class HelloController {
//@GetMapping
//HTTP Method์ธ Get์ ์์ฒญ์ ๋ฐ์ ์ ์๋ API๋ฅผ ๋ง๋ค์ด์ค๋ค.
//์์ ์๋ @RequestMapping(method = RequestMethod.GET)์ผ๋ก ์ฌ์ฉ๋์๋ค.
//์ด์ ์ด ํ๋ก์ ํธ๋ /hello๋ก ์์ฒญ์ด ์ค๋ฉด ๋ฌธ์์ด hello๋ฅผ ๋ฐํํ๋ ๊ธฐ๋ฅ์ ๊ฐ์ง๋ค.
public String hello() {
return "hello";
}
}
์์ฑํ ์ฝ๋๊ฐ ์ ๋๋ก ์๋ํ๋์ง ํ ์คํธ๋ฅผ ํด๋ณธ๋ค. WAS๋ฅผ ์คํํ์ง ์๊ณ ํ ์คํธ ์ฝ๋๋ก ๊ฒ์ฆํด๋ณธ๋ค. java์์ ๋ง๋ ํจํค์ง ๊ทธ๋๋ก test์์๋ ๋ง๋ ๋ค.
์ผ๋ฐ์ ์ผ๋ก ํ ์คํธ ํด๋์ค๋ ๋์ ํด๋์ค์ ์ด๋ฆ์ Test๋ฅผ ๋ถ์ธ๋ค.
'Project > Instagram' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SpringBoot] ๊ฐ๋ฐํ๊ฒฝ ์ค์ (0) | 2020.07.14 |
---|---|
[spring] ํด๋ก ์ฝ๋ฉ19 Interceptor (1) | 2020.04.21 |
[spring] ํด๋ก ์ฝ๋ฉ 18 Follow - ํ๋ก์, ํ๋ก์ ๋ฆฌ์คํธ ์กฐํ (0) | 2020.04.21 |
[spring] ํด๋ก ์ฝ๋ฉ17 Follow - ํ๋ก์ฐ, ์ธํ๋ก์ฐ (0) | 2020.04.20 |
[spring] ํด๋ก ์ฝ๋ฉ16 Follow - Model, Repository, Mapper, Test, Service, Controller (0) | 2020.04.20 |
- Total
- Today
- Yesterday
- ์จ๋ฆฌ์์ค
- ๊ฐ๋ฐํ๊ฒฝ๊ตฌ์ถ
- java ํ๊ฒฝ๋ณ์
- ์ ์ฒด๊ฒ์๋ฌผ ์กฐํ
- ๋ณ๋ช ์ฒ๋ฆฌ
- Java
- mysql์ค์น
- ๊ฒ์๋ฌผ์กฐํ
- ์ดํด๋ฆฝ์ค ํ๊ธ ์ธ์ฝ๋ฉ
- ๊ฒ์ํ๋ง๋ค๊ธฐ
- ๊ฒ์ํ ์ญ์
- ์๋ฐ
- tomcat์ค์น
- ์ดํด๋ฆฝ์ค ์ค์น
- java jdk ์ค์น
- typeAliases
- ๊ฐ๋ฐ
- ๊ฒ์๋ฌผ ์ญ์
- ์คํ๋ง๋ถํธ ์๋์์ฑ
- ๋ถํธ ์๋์์ฑ
- ์๋ฃ๊ตฌ์กฐ
- ๊ฒ์ํ ์กฐํ
- ์๊ณ ๋ฆฌ์ฆ
- Algorithm
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |