【发布时间】:2019-04-05 17:19:31
【问题描述】:
在使用 thymeleaf 渲染我的 html 时,我想要一个整数类型的计数器变量,但计数器变量意外增加。下面是我的代码。请帮忙。
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en"
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div th:with="mycounter = 0">
<div th:with="mycounter=${mycounter + 1}">
<span th:text="${mycounter}"></span> <!-- result: 1 -->
</div>
<div th:with="mycounter=${mycounter + 1}">
<span th:text="${mycounter}"></span> <!-- result: 1 , expected: 2-->
</div>
</div>
</body>
</html>
【问题讨论】:
标签: spring spring-boot thymeleaf counter increment