我使用 spring 3.1 和方法应该返回一个由 jspx 页面表示的视图。在调试时,我在名为的模型中看到变量noteList
,我无法在页面上打印或迭代此变量。
输出是${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>