plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
}
group = 'jpabook'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
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-web'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'mysql:mysql-connector-java'
testImplementation 'junit:junit:4.13.1'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
package jpabook.jpashop;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
@GetMapping("hello")
public String hello(Model model){
model.addAttribute("data", "ㅅㅄㅄ");
return "hello";
}
}
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p th:text="'안녕하세요. ' + ${data}">안녕하세요. 손님</p>
</body>
</html>
스프링 부트 thymeleaf viewName 매핑 → resources:templates/ +{ViewName}+ .html
spring-boot-devtools 라이브러리를 추가하면, html 파일을 컴파일만 해주면 서버 재시작 없이 View 파일 변경 가능
인텔리J 컴파일 방법: 메뉴 build Recompile
# MySQL
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# DB Source URL
spring.datasource.url=jdbc:mysql://localhost:3306/jpapractice
# DB username
spring.datasource.username=root
# DB password
spring.datasource.password=
# DDL(create, alter, drop) auto Option
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.format_sql=true
# Query Log Options
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type=trace
spring.jpa.hibernate.ddl-auto: create
참고
- 모든 로그 출력은 가급적 로거를 통해 남겨야 한다.
show_sql
- 위 옵션은 System.out 에 하이버네이트 실행 SQL을 남긴다.
org.hibernate.SQL
- 위 옵션은 logger를 통해 하이버네이트 실행 SQL을 남긴다.