resources:templates/ +{ViewName}+ .html
Model : 데이터를 실어서 view로 넘긴다.
return "hello";
은 hello.html을 의미package jpabook.jpashop;
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", "hello");
return "hello";
}
}
resources - templates
에 만든다<!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>
localhost:8080/hello
에 들어가 검사 > 소스 보기를 하면 아래처럼 보인다.
resources - static
에 index.html
생성<!DOCTYPE HTML>
<html>
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
<a href="/hello">hello</a>
</body>
</html>
devtools
를 추가.implementation 'org.springframework.boot:spring-boot-devtools'
build - Recompile
을 하면 서버 재실행 없이 웹에서 새로고침을 눌러서 확인할 수 있다.나는 전에 H2 DB를 설치했었다.
h2 - bin
에서 h2.sh
실행
빨간색 부분. key값을 유지해야한다.
URL에 jdbc:h2:~/jpashop
입력 후 연결
좌측에 파일 생성된 것을 확인 할 수 있다.
확인후 연결 끊어서 나오기 (빨간 동그라미)
데이터베이스 파일 생성 이후로는 네트워크 모드로 접근하면 된다.
URL에 jdbc:h2:tcp://localhost/~/jpashop
를 입력 후 연결
create~~ 해서 테이블을 생성 할 수 있다.
command + shift + enter