thymeleaf 와 Model 객체 사용법_sts

2022. 2. 17. 20:05ksmart_Framework/spring

728x90

검색 키워드 : thymeleaf 연결

2022.02.08 - [Framework/springboot] - 스프링부트 개발환경 구축_sts

 

스프링부트 개발환경 구축_sts

 01. 스프링부트 파일 다운로드 더보기 https://github.com/spring-projects/sts4/wiki/Previous-Versions GitHub - spring-projects/sts4: The next generation of tooling for Spring Boot, including support..

moon09-developer.tistory.com

 

  model 객체로 title 값을 넣는다. 

Model 객체를 파라미터로 받아서 데이터를 메인으로 넘길 수 있다.

package ksmart.hellospringboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class MainController {
	
	@GetMapping("/")
	public String main(Model model) {
    	/데이터만 설정 가능
		model.addAttribute("title","ksmart42기");
		return "main";
	}
}

 


  모델객체에 받은 title 값을 main.html 에 값을 넘긴다. 

 

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title th:text="${title}"></title>
</head>
<body>
	<h1>Hello Spring Boot! [[${title}]]</h1>
</body>
</html>
더보기

텍스트 지정의미

키 값

 

 

728x90

'ksmart_Framework > spring' 카테고리의 다른 글

springboot 백업_sts  (0) 2022.02.20
@Service @Autowired 어노테이션, ModelAndView_sts  (0) 2022.02.20
기본문법_sts  (0) 2022.02.17
Hello Spring Boot!_sts  (0) 2022.02.17
스프링부트 개발환경 구축_sts  (0) 2022.02.08