JS에서 model의 값에 접근하고 싶었다.
Thymeleaf의 th:inline을 사용한다.
<script th:inline="javascript">
</script>
스크립트 태그에 th:inline="javascript"를 추가했다.
참고) th:inline의 값으로는 text, none도 있다.
var post_id=[[${post.id}]];
이렇게 사용한다.
Strings, Numbers, Booleans, Arrays, Collections, Maps, Beans(objects with getter and setter methods) 타입을 사용할 수 있다.
참고 👇
https://kimfk567.tistory.com/105
타임리프 js에서 model 데이터 받기 ( th:inline )
현재 타임리프를 사용하고 있지만, 전에는 jsp를 사용했었다. 컨트롤러에서 model을 사용해 프론트로 데이터를 보내면 key값을 이용해 ${key} 이런식으로 값을 가져올 수 있었고, js에서도 마찬가지
kimfk567.tistory.com
https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html
Tutorial: Using Thymeleaf
1 Introducing Thymeleaf 1.1 What is Thymeleaf? Thymeleaf is a Java library. It is an XML/XHTML/HTML5 template engine able to apply a set of transformations to template files in order to display data and/or text produced by your applications. It is better s
www.thymeleaf.org
'FE > html' 카테고리의 다른 글
[Error] 네이버 로그인 API Callback URL (0) | 2022.10.03 |
---|---|
[Error] naver login Uncaught TypeError: Cannot read properties of undefined (reading 'age') (0) | 2022.10.03 |
조회 시 HTML 태그가 출력될 때(feat. Summernote) (0) | 2022.08.04 |
form 외부에서 submit 버튼 (0) | 2022.08.04 |
Uncaught TypeError: $.ajax is not a function (0) | 2022.08.04 |