본문 바로가기

STUDY/SpringBoot+JPA

[스프링부트-JPA-1] 라이브러리 살펴보기, View 환경 설정

인프런 '실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발' 강의를 들으며 정리한 내용입니다.
실습 github : https://github.com/baeji-mil/study-springboot_jpa

1. 라이브러리 살펴보기

라이브러리 조회 방법 : ./gradlew dependencies -configuration compileClasspath

dependencies {
   implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
   implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
   implementation 'org.springframework.boot:spring-boot-starter-validation'
   implementation 'org.springframework.boot:spring-boot-starter-web'
   implementation 'org.springframework.boot:spring-boot-devtools' // re run 하지 않아도 html 업데이트 해줌. 캐시도 제거해줌.
   compileOnly 'org.projectlombok:lombok'
   runtimeOnly 'com.h2database:h2'
   annotationProcessor 'org.projectlombok:lombok'
   testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
  • spring-boot-starter-data-jpa
    • spring-boot-starter-aop
    • spring-boot-starter-jdbc
      • HikariCP 커넥션 풀 (부트 2.0 기본)
    • hibernate + JPA : 하이버네이트 + JPA
    • spring-data-jpa : 스프링 데이터 JPA
  • spring-boot-starter-thymeleaf : 타임리프 템플릿 엔진(View)
  • spring-boot-starter-validation
  •  spring-boot-starter-web
    • spring-boot-starter-tomcat : 톰캣 (웹서버)
    • spring-webmvc : 스프링 웹 MVC
  • spring-boot-devtools : 톰캣 재시작 없이 변경된 html 파일 반영
  • spring-boot-starter(공통) : 스프링부트 + 스프링 코어 + 로깅
    • spring-boot
      • spring-core
    • spring-boot-starter-logging
      • logback, slf4j
  • spring-boot-starter-test
    • junit : 테스트 프레임워크
    • mockito : 목 라이브러리
    • assertj : 테스트 코드 편하게 작성하게 도와주는 라이브러리
    • spring-test : 스프링 통합 테스트 지원

 

2. View 환경 설정

스프링부트 thymeleaf view Name 매핑

-> resources:templates/+{ViewName}+.html

/hello url이 Controller의 @GetMapping("hello")에 매핑되고, return "hello"로 인해 templates/hello.html을 보여준다.

라인8 <p></p> 에 '안녕하세요. 손님' 부분 대신  '안녕하세요! ${data}'가 화면에 표시된다.

hello.html에 ${data}는 컨트롤러에서 model.addAttribute("data", "hello!!") 모델에 담아 넘겨준 hello!! 값이 나타난다.

서버 재시작 없이 html 코드 수정을 반영하기 위해서는 dependency에 spring-boot-devtools를 적용해야 한다.

[restartedMain]이 보이면 spring-boot-devtools가 잘 적용된 것이다!!

Build > Recompile 'hello.html' 선택하면, 페이지 새로고침시 hello.html에서 수정한 내용이 반영된다.

'STUDY > SpringBoot+JPA' 카테고리의 다른 글

[스프링부트-JPA-1] 프로젝트 생성  (0) 2023.01.26