일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- popleft
- 1일1솔
- 소수판별
- C#강의
- 소수찾기
- appendleft
- Python
- 인프런
- 우선순위큐
- pypy3
- 백준
- 그리디 알고리즘
- 완전탐색
- python3
- spring
- DP
- BFS
- c#
- 프로그래머스
- 합 구하기
- Java
- 브루투포스
- 파이썬
- 연관관계
- LCM
- JPA
- 누적합
- deque
- mvc
- unity
Archives
- Today
- Total
jae_coding
[Spring Project] View 환경설정 본문
반응형
목차
- Thymeleaf
- Static Page
- Template Page
1. Thymeleaf 템플릿 엔진 사용
Thymeleaf의 장점: 웹 브라우저에서 열린다. (다른 템플릿은 하지 못한다!)
2. Static Page
resources > static > index.html 생성
<!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>
Hello
<a href="/hello">hello</a>
</body>
</html>
실행화면 (localhost:8080)
Controller를 거쳤을 때, Getmapping이 되지 않았을 때, Static의 index.html실행
3. Template Page
HelloController class
package jpabook.jpashop;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
// for Thymeleaf check
@Controller
public class HelloController {
@GetMapping("hello") // (/hello) url으로 들어오면 hello.html이 호출된다.
public String hello(Model model){
model.addAttribute("data", "hello!");
return "hello"; //hello.html 호출
}
}
Templates > hello.html
<!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)
이런식으로 Thymeleaf 엔진을 이용하여 데이터를 넘겨 html을 호출하는 방법을 알아봤습니다.
반응형
'Spring, java > Spring_Project' 카테고리의 다른 글
[Spring Project] 애플리케이션 아키텍쳐 (0) | 2022.08.22 |
---|---|
[Spring Project] 엔티티 설계 주의사항 (0) | 2022.08.22 |
[Spring Project] 엔티티 클래스 개발 (3) | 2022.08.21 |
[Spring Project] h2 Database 환경설정 (0) | 2022.08.20 |
[Spring Project] 프로젝트 환경설정 (0) | 2022.08.20 |
Comments