기록해! 정리해!

Tymeleaf 구조알기 본문

SpringBoot

Tymeleaf 구조알기

zsuling 2022. 10. 17. 17:58

프로젝트 구조알기

test3를 redirect 사용해서 test4로 불러오기

1.Tymeleaf 프로젝트 생성

 
 

2.pom.xml 추가할 필요 없음

3. application.properties

# 주석 ( none , servlet )
spring.main.web-application-type=servlet
server.port=8001

# 오라클 컨넥션 정보
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url =jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.username=system
spring.datasource.password=1234

####  다중 mapper 설정하기
mybatis.mapper-locations=classpath:mapper/**/*.xml

# Thymeleaf Cache Setting
spring.thymeleaf.cache = false

4. index.html 생성

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 <div align="center">
  <h2> thymeleaf 시작하기  </h2>
  
  <a href=Test1.do> Test1 </a> <br><br>
  <a href=Test2.do> Test2 </a> <br><br>
  <a href=Test3.do> Test3 </a>
 
 </div>
</body>
</html>

5. Controller생성

package com.rubypaper.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TestController {
   
	@RequestMapping("Test1.do")
	public  void  test1() {
		System.out.println("==> test1 ");	
		
	}
	
	@RequestMapping("Test2.do")
	public  String   test2() {
		System.out.println("==> test2 ");	
		
		return "test2.html";		
	}	
	
	@RequestMapping("Test3.do")
	public  String   test3() {
		System.out.println("==> test3 ");	
		
		return "redirect:Test4.do";		
	}
	
	@RequestMapping("Test4.do")
	public  String   test4() {
		System.out.println("==> test4 ");	
		
		return "test3.html";		
	}
	
}

6. Test.html

<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2> Test1.html </h2>
</body>
</html>

7. 결과

 

>>

 

 

Comments