본문 바로가기
728x90
반응형

thymeleaf32

[Spring] 타임리프에서 제공하는 기본 객체들 & 유틸리티 객체와 날짜 기본 객체들 타임리프는 기본 객체들을 제공한다. 스프링 부트 2.0 ${#request} - 스프링 부트 3.0부터 제공하지 않는다. ${#response} - 스프링 부트 3.0부터 제공하지 않는다. ${#session} - 스프링 부트 3.0부터 제공하지 않는다. ${#servletContext} - 스프링 부트 3.0부터 제공하지 않는다. ${#locale} 그런데 #request 는 HttpServletRequest 객체가 그대로 제공되기 때문에 데이터를 조회하려면 request.getParameter("data") 처럼 불편하게 접근해야 한다. 이런 점을 해결하기 위해 편의 객체도 제공한다. HTTP 요청 파라미터 접근: param 예) ${param.paramData} HTTP 세션 접근: s.. 2023. 6. 16.
[Spring] 타임리프 텍스트 - text, utext ( unescaped ) 타임리프의 가장 기본 기능인 텍스트를 출력하는 기능 먼저 알아보자. 타임리프는 기본적으로 HTML 테그의 속성에 기능을 정의해서 동작한다. HTML의 콘텐츠(content)에 데이터를 출력할 때는 다음과 같이 th:text 를 사용하면 된다. HTML 테그의 속성이 아니라 HTML 콘텐츠 영역안에서 직접 데이터를 출력하고 싶으면 다음과 같이 [[...]] 를 사용하면 된다. 컨텐츠 안에서 직접 출력하기 = [[${data}]] BasicController package hello.thymeleaf.basic; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframew.. 2023. 6. 15.
[Spring] 타임리프 특징 및 제공 기능 공식 사이트: https://www.thymeleaf.org/ Thymeleaf Integrations galore Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework. Check out our Ecosystem to see more integrati www.thymeleaf.org 공식 메뉴얼 - 기본 기능: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.htm.. 2023. 6. 15.
[Spring] 타임리프 학습을 위한 프로젝트 생성 https://start.spring.io/에서 프로젝트 선택 Project: Gradle - Groovy Project Language: Java Spring Boot: 2.x.x Project Metadata Group: hello Artifact: thymeleaf-basic Name: thymeleaf-basic Package name: hello.thymeleaf 패키지 이름 지을 땐, 특수기호가 들어가지 않도록 주의해야한다. Packaging: Jar Java: 11 Dependencies: Spring Web, Lombok , Thymeleaf GENERATE build.gradle plugins { id 'java' id 'org.springframework.boot' version '2... 2023. 6. 15.
[Spring] 상품 상세 BasicItemController에 추가 @GetMapping("/{itemId}") public String item(@PathVariable long itemId, Model model) { Item item = itemRepository.findById(itemId); model.addAttribute("item", item); return "basic/item"; } PathVariable 로 넘어온 상품ID로 상품을 조회하고, 모델에 담아둔다. 그리고 뷰 템플릿을 호출한다 상품 상세 뷰 정적 HTML을 뷰 템플릿(templates) 영역으로 복사하고 다음과 같이 수정 /resources/static/item.html → 복사 → /resources/templates/basic/item.html.. 2023. 6. 14.
[Spring] 상품 목록 - 타임리프(Thymeleaf) BasicItemController package hello.itemservice.web.basic; import hello.itemservice.domain.item.Item; import hello.itemservice.domain.item.ItemRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMappin.. 2023. 6. 14.
728x90
반응형