[Spring] Week1 - Section 0~2

pos++·2023년 9월 16일

Spring

목록 보기
1/9
post-thumbnail

Spring Project 생성하기

1) Spring Initializr로 Gradle Project 생성

↳ 이렇게 설정해주겐


Gradle?
Gradle은 의존관계가 있는 라이브러리를 함께 다운로드한다.

<스프링부트 라이브러리>

  • spring-boot-starter-web

    • spring-boot-starter-tomcat: 톰캣 웹서버
    • spring-webmvc: 스프링 웹 MVC
  • spring-boot-starter-thymeleaf

  • spring-boot-starter(공통): 스프링부트 + 스프링 코어 + 로깅

    • spring-boot

      • spring-core
    • spring-boot-starter-loggint

      • logback, slf4j

<테스트 라이브러리>

  • spring-boot-starter-test
    • junit: 테스트 프레임워크
    • mockito: 목 라이브러리
    • assertj: 테스트코드 편하게 작성하게 도와줌
    • spring-test: 스프링 통합 테스트 지원

View 설정하기

스프링부트의 Welcome Page 기능

src > main > resources > static 폴더 > index.html 생성

Controller 생성하기

src > main > hello.hellospring > controller package 생성 > HelloController class 생성
Controller에서 return값으로 문자를 반환하면 viewResolver가 화면을 찾아서 처리함.

SpringBoot Template Engine 기본 viewName mapping
resources:templates/ + {viewName} + .html

src > main > resources > templates 폴더 > hello.html 생성


Build, 실행파일 만들기

-> 서버에 배포할 때는 hello-spring-0.0.1-SNAPSHOT.jar 파일만 복사해서 서버에 넣고,

java -jar hello-spring-0.0.1-SNAPSHOT.jar 해서 실행시키면 된다!


clean build

프로세스 종료 단축키: control + C


MVC 패턴이란?

템플릿 엔진을

Model: 비즈니스로직 관련
View: 화면을 그리는데에 집중
Controller: 내부적인 것들

로 쪼개서 view를 html을 좀 더 렌더링해서 내려준다!

viewResolver:
view를 찾아주고, 템플릿 엔진을 연결시켜주고 처리해달라고 넘김
-> 변환해서 web browser에 넘겨줌


API와 서버

MVC 방식: view를 찾아서 html을 내려주는 방식
API 방식: data를 바로 내리는 방식 (json)

viewResolver 대신에 HttpMessageConverter가 동작

  • 기본 문자처리: StringHttpMessageConverter
  • 기본 객체처리: MappingJackson2HttpMessageConverter

RESTful 이란?

REST API를 제공하는 웹서비스 -> RESTful

REST (Representational State Transfer)
: 자원을 이름으로 구분하여 해당 자원의 상태(정보)를 주고 받는 것.

  • HTTP URI를 통해 자원을 명시
  • HTTP Method - GET, PUT, POST, DELETE 를 통한 CRUD


강의: 스프링 입문 - 코드로 배우는 스프링부트, 웹 MVC, DB 접근 기술 (김영한)

profile
밀린 TIL 업로드 조금씩 정리중...

0개의 댓글