Welcome Page 기능
스프링 부트가 제공하는 기능
static/index.html 을 작성하면 Welcome page 기능을 제공
처음 SpringBoot를 다운로드 받을때 추가한 dependencies에 thymeleaf가 있다
<html xmlns:th="http://www.thymeleaf.org"
html파일에서 다음과 같이 선언하고
<p th:text="Java"></p>
이렇게 간단한 text나
<tr th:each="javaBoard: ${javaBoards}">
each문도 사용할 수 있다 jstl과 비슷한거같다
@Controller
public class HelloController {
@GetMapping("mvc")
public String helloMvc(@RequestParam("name") String name, Model model){
model.addAttribute("name",name);
return "mvc-template";
}
}
@Controller 어노테이션을 붙이고
mvc라는 GetMapping이 오면 파라미터 name을 가지고 mvc-template로 return한다
(resourse -> templates -> mvc-template)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p th:text="hello + ${name}"> hello! empty</p>
</body>
</html>
mvc-template.html이다
주소창에 localhost:포트번호와 mvc?name=입력할단어▶
이렇게 하면 mvc-template.html로 넘어와
위처럼 p태그 th:text에 hello + 입력한 값이 화면에 표시된다
웹 브라우저
▼
localhost:8082/mvc?name=
▼
톰켓 서버
▼
(스프링 컨테이너)
HelloController
return mvc-template
model( name : spring )
▼
viewResolver
templates/mvc-template ( Thymeleaf 템플릿 엔진 처리 )
▼
mvc-template .html 변환 후
▼
웹 브라우저
컨트롤러에서 리턴 값으로 문자를 반환하면 viewResolver가 화면을 찾아서 처리
접두사 + html파일 + 접미사로 resources:templates/ + (viewname) . html 으로 매핑된다
'Spring' 카테고리의 다른 글
[SpringBoot/IntelliJ] MVC구조 ( 게시판 예제 ) (0) | 2022.04.14 |
---|---|
[Spring Boot/IntelliJ] ResponseBody to JSON (0) | 2022.04.13 |
[Spring Boot/IntelliJ] SpringBoot 시작 (0) | 2022.04.13 |
Spring - mysql 연동 환경설정 (0) | 2021.05.24 |
Android에서 연동 (0) | 2021.04.30 |