在controller中查询出了一个数据,数据关联了另外一个对象,在页面中用A.GETB().GETXXX()的方式的时候就会报错,因为是懒加载,默认的session已经关闭了。
解决方案:在web.xml配置文件中加入以下内容
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
.