如何在html页面中使用Java for循环
在我的系统中,我需要在html表中使用java for循环来打印8.00-17.00之间的时间。谁能告诉我怎么做吗?谢谢 Html文件如何在html页面中使用Java for循环,java,html,spring-boot,thymeleaf,Java,Html,Spring Boot,Thymeleaf,在我的系统中,我需要在html表中使用java for循环来打印8.00-17.00之间的时间。谁能告诉我怎么做吗?谢谢 Html文件 <!DOCTYPE html> <html xmlns:th="https://www.thymeleaf.org"> <head> <link rel="stylesheet" type="text/css" href="static/css/timeTable.css" th:href="@{/css/tim
<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org">
<head>
<link rel="stylesheet" type="text/css" href="static/css/timeTable.css" th:href="@{/css/timeTable.css}">
<meta charset="UTF-8">
<title>Time Table</title>
</head>
<body>
<div class="container" style="margin-top:30px">
<br><br>
<table border="1" class="table2">
<thead>
<tr>
</tr>
<br>
<tr>
<td></td>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
</tr>
</thead>
<tbody>
<tr>
<% for(int i=0;i<17;i++){
<td> i.":00 - ".($i+1).":00" </td>
}
</tr>
</tbody>
</table>
</div>
</body>
</html>
时间表
星期一
星期二
星期三
星期四
星期五
您应该按如下方式安装JSTL:
<c:forEach var = "i" begin = "8.00" end = "17.00">
Item <c:out value = "${i}"/><p>
</c:forEach>
然后按如下方式迭代列表:
<c:forEach var = "i" begin = "8.00" end = "17.00">
Item <c:out value = "${i}"/><p>
</c:forEach>
项目
我可以通过以下方法来完成。谢谢所有想帮忙的人
<option th:each="i : ${#numbers.sequence( 8, 17)}">
<tr>
<th th:text="${ i }+':00 - ' + ${ i+1 }+':00'"></th>
</tr>
</option>
你为什么不使用Javascript而不是疯狂地发明这样的东西呢? Javascript是一种功能强大的语言,并且具有for循环。
让我们转到属于前端的前端。这必须是一个JSP文件(尽管javascript也可以工作)。此外,您还缺少结束语
%>
如何添加jsp文件?谢谢你看起来你在用thymeleaf。因此,使用thymeleaf,您可以使用th:each
进行迭代,而不需要jsp文件。如何仅使用th:each.jsp文件进行类似的迭代,或者您可以使用javascript并在html页面上呈现它。