3.2.3 inline 속성
타임리프의 속성 중 가장 유용한 기능인 inline 속성입니다. inline 속성은 자바스크립트에서 유용합니다.
@GetMapping({"/exInline"})
public String exInline(RedirectAttributes redirectAttributes){
log.info("exInline.......");
SampleDTO dto = SampleDTO.builder().sno(100L).first("First...100").last("Last...100").regTime(LocalDateTime.now()).build();
redirectAttributes.addFlashAttribute("result","success");
redirectAttributes.addFlashAttribute("dto",dto);
return "redirect:/sample/ex3";
}
@GetMapping("/ex3")
public void ex3(){
log.info("ex3");
}
RedirectAttribute를 이용하여 /ex3으로 result와 dto라는 이름의 데이터를 심어서 전달합니다.
<h1 th:text="${result}"></h1>
<h1 th:text="${dto}"></h1>
<script>
var msg = [[${result}]];
var dto = [[${dto}]];
</script>
sample/exInline으로 호출시 보여지는 화면은 다음과 같습니다.
리다이렉트 되기 때문에 sample/ex3을 다시 호출하고, 결과 페이지를 다음과 같이 보여줍니다.
별도의 처리가 없어도 문자열은 자동으로 ""이 추가되어 문자열이 됩니다.
같이 전송된 dto는 JSON 포맷의 문자열이 된 것을 볼 수 있습니다.
th:block
th:block은 별도의 태그가 필요하지 않기 때문에 반드시 태그에 붙여서 th:text나 th:value등을 써야하는 제약이 없습니다.
sno가 5로 나눈 나머지가 0인 경우에는 sno를 출력하고 그렇지 않다면 first를 출력하기
728x90
'🏰 Back-end > Spring Boot' 카테고리의 다른 글
[Spring Boot] 타임리프의 레이아웃 (0) | 2021.07.21 |
---|---|
[Spring Boot] 링크 처리 (0) | 2021.07.18 |
[Spring Boot] 제어문 처리 (0) | 2021.07.16 |
[Spring Boot] 반복문의 상태 객체 (0) | 2021.07.15 |
[Spring Boot] Thymeleaf의 기본 사용법 (0) | 2021.07.14 |
댓글