JSTL标签(简化JSP中java代码的书写)之if test和for each的使用
首先要引入坐标,并且在JSP页面上导入库
值的判断要放在{}里面,和EL表达式取出来的放在一起才可以
Varstatus的作用
id在数据库中是主键值,有可能因为数据的删除而导致不连续,为了在页面上显示的序号是连续的,可以使用Varstatus属性。
产生网页分页工具条的功能![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/31ea781cd36cc7079c971d70d5afabdb.png)
例子:
<%--
Created by IntelliJ IDEA.
User: 南理工张佳成
Date: 2021/12/12
Time: 17:32
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="button" value="新增"><br>
<hr>
<table border="1" cellspacing="0" width="800">
<tr>
<th>序号</th>
<th>品牌名称</th>
<th>企业名称</th>
<th>排序</th>
<th>品牌介绍</th>
<th>状态</th>
<th>操作</th>
</tr>
<c:forEach items="${brands}" var="brand" varStatus="status">
<tr>
<td>${status.count}</td>
<td>${brand.brandName}</td>
<td>${brand.companyName}</td>
<td>${brand.ordered}</td>
<td>${brand.description}</td>
<c:if test="${brand.status==1}">
<td>启用</td>
</c:if>
<c:if test="${brand.status!=1}">
<td>禁用</td>
</c:if>
<td><a href="#">修改</a> <a href="#">删除</a></td>
</tr>
</c:forEach>
</table>
</body>
</html>