타임리프로 받아온 값 자바스크립트에서 사용하는 방법!

타임리프 3.0 버전부터 아래 문법으로 바뀜

공식 문서 참조 : https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html

 

사용법

1. <script>에 th:inline="javascript" 붙이기

2. 타임리프 값 [[ ]]; 로 감싸기

 

예시

<script th:inline="javascript">
    let x = [[${cafeDetailResponseDto.getCafeX()}]];
    let y = [[${cafeDetailResponseDto.getCafeY()}]];
</script>

 

+ Recent posts