我帶彈簧3.1和方法的工作應該返回由JSPX頁面所代表的觀點得到模型變量。在調試時,我看到名爲noteList
的模型中的變量,我無法在頁面上打印或迭代此變量。不能在JSPX頁面
輸出爲${noteList}
。
下面是一些代碼:
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView rootPage(){
List<Note> result = sessionFactory.openSession().createCriteria(Note.class).list();
ModelAndView mv = new ModelAndView("index");
mv.addObject(result);
return mv;
}
<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:spring="http://www.springframework.org/tags" version="2.0">
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
<![CDATA[<!DOCTYPE html>]]>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Index page</title>
</head>
<body>
<c:out value="${noteList}"/>
</body>
</html>
</jsp:root>
<beans:bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jspx" />
</beans:bean>
這樣沒有幫助過。 頁面只顯示「$ {node}」。並且列表中只有一個對象。 –