1. 프로젝트 환경설정
간단한 웹 애플리케이션 개발
스프링 프로젝트 생성
스프링 부트로 웹 서버 실행
회원 도메인 개발
웹 MVC 개발
DB 연동 - JDBC, JPA, 스프링 데이터 jpq
테스트케이스 작성
프로젝트 생성
스프링 관련 프로젝트를 만들어주는 사이트
Project: Gradle Project
Spring Boot: 2.3x
Language: Java
Packaging: Jar
Java: 11
html 만들어주는 템플릿 엔진: thymeleaf
IntelliJ에서 프로젝트 열기
build.gradle
main - java - HelloSpringApplication 실행
File - Settings - gradle 검색 후 IntelliJ로 바꾸기
라이브러리 살펴보기
스프링 부트 라이브러리
- Spring-boot-starter-web
- spring-boot-starter-tomcat: 톰캣(웹서버)
- spring-webmvc: 스프링 웹 MVC
- spring-boot-starter-thymeleaf: 타임리프 템플릿 엔진(View)
- spring-boot-starter(공통): 스프링 부트 + 스프링 코어 + 로깅
- spring-boor : spring-core
- spring-boot-starter-logging: logback, slf4j
테스트 라이브러리
- spring-boot-starter-test
- junit: 테스트 프레임워크
- mockito: 목 라이브러리
- assertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리
- spring-test: 스프링 통합 테스트 지원
View 환경설정
Welcome Page 만들기
src - main - resources - static - index.html
thymeleaf 템플릿 엔진
thymeleaf 공식 사이트: https://www.thymeleaf.org/
스프링 공식 튜토리얼: https://spring.io/guides/gs/serving-web-content/
스프링부트 메뉴얼: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/
hello.hellospring 밑에 controller 패키지 만들기 - HelloController 클래스 생성
src - main - resources - templates 밑에 hello.html 만들기
localhost:8080/hello 실행
동작 환경 그림
컨트롤러에서 리턴 값으로 문자를 반환하면 뷰 리졸버( viewResolver )가 화면을 찾아서 처리한다.
스프링 부트 템플릿엔진 기본 viewName 매핑
resources:templates/ +{ViewName}+ .html
빌드하고 실행하기
CMD 창에서 실행
1. ./gradlew build
2. cd build/libs
3. java -jar hello-spring-0.0.1-SNAPSHOT.jar