C标签
C:foreach foreach可以配合el表达式将需要的数据遍历显示出来。 这次有个需求是需要做一个下拉框,下拉框中的数据取自数据库中的一列字段。这里可以使用foreach进行实现。
下面贴上代码。思路是先从数据库中取出你需要的数据,然后传递到JSP中,命名为paraminfo。 在加载index的时候数据已经传递过去了。直接调用paraminfo就行。
<select > <option>30S</option> <c:forEach items="${paraminfo}" var="item"> <option value="${item.paramvalue }">${item.paramvalue}s</option> </c:forEach> </select>
@RequestMapping("/index.html") public String index( Model model) throws Exception { Paraminfo pf = new Paraminfo(); List<Paraminfo> pfList = iSerParaminfo.selectByCondition(pf); //System.out.println("1111111111ssss"+pfList); model.addAttribute("paraminfo",pfList); return "special/fault/record/index"; }
C;if 可以用来将数据库中用0-1等字符代替的定义显示出来,比如0代替否,1代替是。
例子:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>taglib</title>
</head>
<body>
<c:if test="${1<2}">
<c:out value="1<2 is true"/>
</c:if>
<c:if test="${1>2}">
<c:out value="1>2 is false"/>
</c:if>
</body>
</html>