교육자료
https://www.youtube.com/watch?v=P6AgXuh-fxA&list=PLumVmq_uRGHgBrimIp2-7MCnoPUskVMnd&index=4
<!DOCTYPE HTML>
<html lang="ko">
<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>
static 에 index.html 로 메인 페이지 기본 view 생성
화면 좌측 하단 정지 실행으로 서버 재실행 후 확인
버전별 제작 문서 확인 가능
동적 페이지 제작
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
// /hello 로 get 주소 입력시 아래 소스 매핑하라는 명령어
@GetMapping("hello")
public String hello(Model model){
model.addAttribute("data","hello!!"); //모델에 정보담아서 세팅
return "hello"; //hello.html로 model 데이터 전달 명령어
}
}
java/hello.hellospring/controller/HelloController 제작
<!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>
templete/hello.html 제작
컨트롤러 return 시 뷰 리졸버가 리소스/templates에 / "뷰네임 변수" .html 로 데이터 전달!
데이터 보내느 형식
public String hello(Model model){
model.addAttribute("data","hello!!"); //모델에 정보담아서 세팅
return "hello"; //hello.html로 model 데이터 전달 명령어
}
데이터 받는 형식
<p th:text="'안녕하세요.'+${data}">안녕하세요. 손님</p>
'개발 > spring' 카테고리의 다른 글
spring get데이터 받기 처리 (0) | 2022.11.24 |
---|---|
빌드하고 실행하기 (0) | 2022.11.24 |
스프링 라이브러리 살펴보기 톰켓 설치없이 바로 locallhost에 소스를 띄울 수 있는 이유에 대하여 (0) | 2022.11.24 |
스트링 부트 프로젝트 생성 및 실행 (0) | 2022.11.24 |
intellij 설치 (0) | 2022.11.24 |
댓글