일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
- BOJ
- HTTP
- n타일링2
- inflearn
- 운영체제
- 열혈 TCP/IP 소켓 프로그래밍
- 스프링 핵심 원리
- 스프링 입문
- Window-Via-c/c++
- 열혈 tcp/ip 프로그래밍
- 에러핸들링
- TCP/IP
- 2475번
- Operating System
- 제프리리처
- 10026번
- Spring
- redis
- Operating System.
- 김영한
- 우아한 테크 세미나
- Four Squares
- C++
- OS
- C#
- FIFO paging
- 토마토
- 이펙티브코틀린
- 윤성우 저자
- 우아한레디스
- Today
- Total
나의 브을로오그으
#1-2. [스프링 입문] - 프로젝트 설정 본문
[resources/templates/hello.html]
[hellospring/controller/HelloController]
[실행]
스프링 애플리케이션 실행 -> 웹브라우저 주소창에 입력 : localhost:8080/hello
[동작원리]
1. localhost:8080에서 /hello라고 웹브라우저에서 서버로 전달
2. 스프링 부트에는 톰켓이라는 서버를 내장하고 있다. 따라서 서버에서 이걸 받아서 /hello가 있는지 스프링 컨테이너의 Controller에 @GetMapping("hello") = HTTP GET Request임. 이 문자열(url)에 매핑이 되어 있어서 hello()메소드가 실행된다.
3. 이때 model이라는 파라미터는 Spring Container에서 인자로 넘겨주는 것임. 여기다가 model.addAttribute()메소드를 호출해서 'attributeName'인 data에 'attributeValue'로 hello!!를 넘겨줌. 그리고 hello를 return함.
4. return 한 문자열에 해당하는 html 파일을 viewResolver가 templates패키지에서 찾아서 템플릿 엔진(Thymeleaf)이 처리하게 됨.
5. 이것을 웹브라우저에서 랜더링
※ `spring-boot-devtools` 라이브러리 추가 시 `.html` 파일을 컴파일만 해주면 서버 재시작 없이 View 파일 변경 가능
인텔리J 컴파일은 build -> Recompile
[콘솔에서 뷜드 -> 실행]
1. 콘솔로 이동
2. ./gradlew build
3. cd build/libs
4. java -jar hello-spring-0.0.1-SNAPSHOT.jar
5. 실행 확인
서버 배포 : [SpringApplicationName]-[Version]-SNAPSHOT.jar만 배포하면 됨.
(만약 안될경우 프로젝트디렉터리에 가서 gradlew build clean한 후 다시 뷜드 진행)
'Spring' 카테고리의 다른 글
#4. [스프링 입문] - 스프링 빈과 의존관계 (0) | 2022.07.10 |
---|---|
#3. [스프링 입문] - 간단한 앱 개발 (0) | 2022.07.10 |
#2. [스프링 입문] - 스프링 웹 개발 기초 (0) | 2022.07.09 |
#1-1. [스프링 입문] - 프로젝트 설정 (0) | 2022.07.09 |
#0. [스프링 입문] - 강의 소개 (0) | 2022.07.01 |