Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Linux
- JPA
- Spring Cloud Netflix
- 자바 ORM 표준 JPA 프로그래밍 정리
- @Transactional Propagation
- git
- intellij 즐겨찾기
- 마이크로 서비스
- #docker compose
- ksqldb
- 친절한 SQL 튜닝
- HandlerMethodArgumentResolver
- aws
- 자바 ORM 표준 JPA 프로그래밍
- intellij 핵심 단축키
- multipart테스트
- ksql
- CompletableFuture
- intellij favorites
- Stream
- 백명석님
- @TransactionalEventListener
- 원격 브랜 삭제
- 리팩토링 2판
- findTopBy
- IntelliJ
- java
- 리눅스
- javascript case
- vue.js
Archives
- Today
- Total
시그마 삽질==six 시그마
Thymeleaf 사용법 1탄 본문
Spring 진영에서 밀어주고 있는 Thymeleaf는 server side 템플릿 엔진이다.
스프링부트 사용시 하단 추가
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
@Data
public class Person {
private String name;
private int age;
private int height;
private List<Car> carList;
public Person(Builder builder) {
this.name = builder.name;
this.age = builder.age;
this.height = builder.height;
this.carList = builder.carList;
}
public static class Builder {
private String name;
private int age;
private int height;
private List<Car> carList;
public Builder(String name) {
this.name = name;
}
public Builder age(int age) {
this.age = age;
return this;
}
public Builder height(int height) {
this.height = height;
return this;
}
public Builder car(List<Car> carList) {
this.carList = carList;
return this;
}
public Person build() {
return new Person(this);
}
}
}
@Data
public class Car {
String name;
public Car(String name) {
this.name = name;
}
}
@RequestMapping("/")
@Controller
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String hello(Model model) {
List<Person> list= Arrays.asList(
new Person.Builder("정우성").age(30).height(180).car(Arrays.asList(new Car("소나타"),new Car("아반테"),new Car("넥소"))).build()
,new Person.Builder("원빈").age(19).height(181).car(Arrays.asList(new Car("소나타"),new Car("아반테"),new Car("BMW"))).build()
,new Person.Builder("이정").age(22).height(180).car(Arrays.asList(new Car("아반테"),new Car("그랜져"),new Car("페라리"))).build()
);
Person person=new Person.Builder("장동건").age(30).build();
model.addAttribute("list", list);
model.addAttribute("person", person);
return "hi";
}
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Hello Thymeleaf</title></head>
<body>
<div th:text="'Test name: ' + ${person.name} + '님'"></div>
<div th:text="'Test age: ' + ${person.age} + '님'"></div>
<table border="1">
<th>이</th>
<th>나이</th>
<th>키</th>
<th>자동차</th>
<tr th:each="item : ${list}">
<td th:text="${item.name}"></td>
<td th:text="${item.age}"></td>
<td th:text="${item.height}"></td>
<td>
<p th:each="car,status : ${item.carList}">
<span th:text="'index:'+${status.index}"></span>
<span th:text="'count:'+${status.count}"></span>
<span th:text="'current:'+${status.current}"></span>
<span th:text="'size:'+${status.size}"></span>
<span th:text="'even:'+${status.even}"></span>
<span th:text="'odd:'+${status.odd}"></span>
<span th:text="'first:'+${status.first}"></span>
<span th:text="'last:'+${status.last}"></span>
<span th:text="'name:'+${car.name}"></span>
</p>
</td>
</tr>
</table>
</body>
</html>
결과
'프로그래밍 > theamleaf' 카테고리의 다른 글
Thymeleaf 사용법 3탄 (0) | 2020.04.30 |
---|---|
Thymeleaf 사용법 2탄(Thymeleaf Layout Dialect) (0) | 2020.04.29 |
Comments