有一个关于JSTL标签的非常简单的问题。 我使用spring从后端获取数据并在JSP中显示。
拥有以下代码。我正在获取控制台中打印的每个标签的项目。但是相同的项目不会在表格行中打印/显示。
<table id="table_id" class="display">
<thead>
<tr>
<th>Movie Name</th>
<th>Movie Rating</th>
</tr>
</thead>
<tbody>
<c:forEach items="${model.movieslist}" var="movie">
<tr>
<td>${movie.name}</td>
<td>${movie.rating}</td>
</tr>
</c:forEach>
</tbody>
我的春季控制器课程
public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
// TODO Auto-generated method stub
logger.info("returning hello view");
List<Movie> moviesList = DbManager.getInstance().getMovies();
ModelMap modelMap = new ModelMap();
modelMap.addAttribute("movieslist", moviesList);
return new ModelAndView("hello.jsp",modelMap);
}
电影域类
package springapp.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "movie")
public class Movie {
@Id
public String _id;
public String name;
public String getId() {
return _id;
}
public void setId(String _id) {
this._id = _id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getRating() {
return rating;
}
public void setRating(float rating) {
this.rating = rating;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public float rating;
public String date;
@Override
public String toString() {
// TODO Auto-generated method stub
return name;
}
}
答案 0 :(得分:0)
首先,你的jsp应该包含以下taglib
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
其次,您不需要使用$ {model.moviesList}来获取它,修改如下:
<c:forEach items="${movieslist}" var="movie">