在Student类中,构造函数带有一些值。我想在VIP栏中打印是或否。当布尔值为public class Student {
private String firstName;
private String lastName;
private boolean goldCustomer;
public Student(String firstName, String lastName, boolean goldCustomer) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.goldCustomer = goldCustomer;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public boolean isGoldCustomer() {
return goldCustomer;
}
public void setGoldCustomer(boolean goldCustomer) {
this.goldCustomer = goldCustomer;
}
}
时为是,反之亦然。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.* , com.jsptag.demo.Student" %>
<%
List<Student> students = new ArrayList< >();
students.add( new Student("Rahul" , "Rawat" , false));
students.add( new Student("Rohit" , "Negi" , true));
students.add( new Student("Mahesh" , "Gupta" , false));
pageContext.setAttribute("myStudents", students);
%>
<html>
<body>
<table border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>VIP ?</th>
</tr>
<c:forEach var="data" items="${myStudents}">
<tr>
<td>${data.firstName}</td>
<td>${data.lastName}</td>
<td>${data.goldCustomer}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
我的JSP页面
_PARTITIONTIME>=&PARTITIONDATE
答案 0 :(得分:4)
它应该与三元运算符一起使用:
<td> ${data.goldCustomer ? 'Yes' : 'No'} </td>