기억은 휘발성 메모리

chapter 05. Thymeleaf 본문

Program Language/String Boot

chapter 05. Thymeleaf

하상엽 2018. 4. 30. 12:59

이전

Model Controller 연동


HTML5

CSS(Bootstrap)

JAVA Script(jQuery)

(화면처리)

Java               ->    템플릿엔진    -> HTML

자바에서 주는 값을 HTML로 변환


라이브러리

1. Thymeleaf

2. Web

3. DevTools(controller가 변경되어 저장되면 값이 변경경됨)


https://docs.google.com/forms/d/e/1FAIpQLScVPOj3-7jIrNjB8HLImsPY5EycthtqXMjH5hCSSXaZPsLbqw/viewform

https://blog.naver.com/conaca


html을 제외한 모든것 ex) image sound

Error404


<html>

<head>


</head>


<body>


<JavaScript> //속도가 빠름(but 비표준)

</JavaScript>

</body>

</html>



@Controller

public class SampleController {


@GetMapping("/sample1")

public void sample1(Model model) {

model.addAttribute("greeting", "Hello World!");

}

}



<!--

<html xmlns:th="http:www.thymeleaf.org">


<head>

<title>Thymeleaf3</title>

<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />

</head>

<body>

<h1>Thymeleaf Test Page</h1>

</body>

</html>

-->


자바 객체를 화면에 출력 -> toString();


*Today hot 리스트를 화면에 출력

리스트or 다량객체(콜렉션)

controller가 restcontroller가 아니면 html을 요구

(템플릿엔진)html + model = view



<!-- smaple3

<html xmlns:th="http:www.thymeleaf.org">

<head>

<title>Thymeleaf3</title>

<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />

</head>


<body>

<div th:each="member, iterState : ${list}">

<h2 th:text="${iterState.index}"></h2>

<h2 th:text="${member.mname}">길동이 이름</h2>

</div>

</body>


</html>

-->


public class Member {

private int mno;

private String mid;

private String mpw;

private String mname;

private Timestamp regdate;

}



@Controller


public class SampleController {


@GetMapping("/sample1")


public void sample1(Model model) {


model.addAttribute("greeting", "안녕하세요!");


}

@GetMapping("/sample2")


public void sample2(Model model) {

Member member = new Member(123,

"user00",

"p00",

"홍길동",

new Timestamp(System.currentTimeMillis()));

model.addAttribute("member", member);

}

@GetMapping("/sample3")

public void sample3(Model model) {

List<Member> listMember = new ArrayList<>();

for(int i = 0; i < 10; i++) {

listMember.add(new Member(123,

"u0" + i,

"p0" + i,

"홍길동" + i,

new Timestamp(System.currentTimeMillis())));

}

model.addAttribute("list", listMember);

}



}

Comments