본 문서는 인프런의 실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발 (김영한) 강의를 공부하며 작성한 개인 노트입니다.
spring-boot-starter-web
spring-boot-starter-test
@Controller
public class HelloController {
@GetMapping("hello") // localhost:8080/hello 주소로 접속
public String hello(Model model) {
model.addAttribute("data", "hello!");
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>
build.gradle에 dependencies 추가
dependencies {
...
implementation 'org.springframework.boot:spring-boot-devtools'
...
}
1.4.200 버전 설치
terminal: cd h2 > cd bin > cat h2.sh > ./h2.sh
팝업 창:
src/main/resources/application.properties 삭제. application.yml 생성
spring:
...
jpa:
hibernate:
ddl-auto: create
...
logging:
level:
org.hibernate.SQL: debug
@Repository
public class MemberRepository {
@PersistenceContext
private EntityManager em;
public Long save(Member member) {
em.persist(member);
return member.getId();
}
public Member find(Long id) {
return em.find(Member.class, id);
}
}
cmd+shift+T > test 자동생성
@RunWith(SpringRunner.class)
@SpringBootTest
class MemberRepositoryTest {
@Test
@Transactional
void save() {
}
@Test
void find() {
}
}