spring boot thymeleaf常用方式

时间:2022-05-06
本文章向大家介绍spring boot thymeleaf常用方式,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

动态和静态区别

静态页面的return默认是跳转到/static/index.html,当在pom.xml中引入了thymeleaf组件,动态跳转会覆盖默认的静态跳转,默认就会跳转到/templates/index.html,注意看两者return代码也有区别,动态没有html后缀。

拼接这样一个URL:/blog/delete/{blogId} 

第一种:th:href="'/blog/delete/' + ${blog.id }" 
第二种:th:href="${'/blog/delete/' + blog.id }" 

js中使用for循环

<script type="text/javascript" th:inline="javascript">

    /* <![CDATA[ */

    for(var i=1;i<3;i++){

        alert(i);

    }

    /* ]]> */

</script>

js中取出数据

<script th:inline="javascript">
</script>
var gid = /*[[${gid}]]*/ 0;