将jsp.vm修改,添加froeach
<!-- 列表 -->
<div id="right">
<button type="button" class="btn btn-primary" onclick="showAddDiv()">新增</button>
<table class="table table-bordered">
<thead>
<tr>
#foreach(${e} in ${columnList})
<th>${e.columnComment}</th>
#end
<th>删除</th>
<th>编辑</th>
</tr>
</thead>
<tbody>
<!-- EL表达式-翻课本 -->
<!-- List<User> row.id 这个id就是后台传来的User里面的属性名 -->
<c:forEach items="#literal()${#end pageInfo.list }" var="row">
<tr>
#foreach(${e} in ${columnList})
<td>#literal()${#end row.${attrName} }</td>
#end
<td><a href="#" class="btn btn-primary" onclick="deleteUser(#literal()${#end row.id})">删除</a></td>
<td><a href="#" class="btn btn-primary" onclick="edit(#literal()${#end row.id})">编辑</a></td>
</tr>
</c:forEach>
</tbody>
新增的地方也要修改,添加froeach
<div class="box">
<div id="loginDiv">
<p class="logTitle">新增</p>
<div>
<form id="saveForm">
<input type="hidden" name="id" id="id" value="0" />
#foreach(${e} in ${columnList})
<div class="formInput">
<span>${e.columnComment}:</span>
<input type="text" name="${e.attrName}" id="${e.attrName}" />
</div>
#end
<input class="formButton" type="button" value="保存"
onClick="create()" />
</form>
</div>
</div>
</div>
运行 http:/ /localhost:8080/shop/user/list.do

http:// localhost:8080/shop/menu/list.do 这是一个管理页面

本文介绍如何在JSP中使用foreach循环动态生成表格和表单元素,包括从后端获取数据并显示在前端的方法。通过示例代码详细展示了如何在列表页面中展示动态数据,以及如何在新增或编辑页面中生成动态表单。
1052

被折叠的 条评论
为什么被折叠?



