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;
原文地址:https://www.cnblogs.com/jiangwz/p/8487068.html