FE/html

JavaScript에서 model 값 가져오기

잔망루피 2022. 8. 13. 21:56
반응형

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

 

반응형