使用此代码
<c:forEach var="row" varStatus="loop" items="${court.monday}">
<tr>
<c:choose>
<c:when test='${row eq "Free Court"}'>
<td class="inner">${loop.index} is Bookable </td>
</c:when>
<c:otherwise>
<td class="inner">${row}</td>
</c:otherwise>
</c:choose>
</tr>
</c:forEach>
基本上,我有一个Timetable对象,其中包含7个字符串数组列表。我可以只用
遍历列表<td class="inner">${row}</td>
但我想检查行值是否等于'Free Court'。如果是,则显示链接。如果没有,则显示事件。我收到以下错误。
'$ {court.monday}'在类型java.lang.String上找不到属性'monday'
我认为这与将ArrayList与String进行比较有关,但我尝试过像row [loop.index]这样的东西(如果我输出它就会正确显示。
这是控制器
@RequestMapping(value = "/gotoCourt", method=RequestMethod.POST)
public String chooseCourt(Model model, HttpServletRequest request){
model.addAttribute("court", timetableService.getById(request.getParameter("courtID")));
return "court";
}
时间表类是
public class MonaleenTTV1 implements Timetable {
@Id
@GeneratedValue
private int id;
@Size(min=5, max=10, message="Court must be between 5 and 10 characters",groups={PersistenceValidationGroup.class, FormValidationGroup.class})
private String name;
@NotNull
//@Min(value = 1, message="Value must be 1 or greater")
private int slots;
private int startTime;
private int endTime;
private boolean enabled;
@ElementCollection
@CollectionTable (name = "monday", joinColumns=@JoinColumn(name="id"))
List<String> monday;
@ElementCollection
@CollectionTable (name = "tuesday", joinColumns=@JoinColumn(name="id"))
List<String> tuesday;
@ElementCollection
@CollectionTable (name = "wednesday", joinColumns=@JoinColumn(name="id"))
List<String> wednesday;
@ElementCollection
@CollectionTable (name = "thursday", joinColumns=@JoinColumn(name="id"))
List<String> thursday;
@ElementCollection
@CollectionTable (name = "friday", joinColumns=@JoinColumn(name="id"))
List<String> friday;
@ElementCollection
@CollectionTable (name = "saturday", joinColumns=@JoinColumn(name="id"))
List<String> saturday;
@ElementCollection
@CollectionTable (name = "sunday", joinColumns=@JoinColumn(name="id"))
List<String> sunday;
答案 0 :(得分:0)
唉!我的代码没有错。重新启动Tomcat使它工作! :)