读书人

struts2 + json +hibernate的推迟失效

发布时间: 2012-08-30 09:55:54 作者: rapoo

struts2 + json +hibernate的延迟失效

在项目中使用SSH框架开发时,可以在web.xml中配置session为页面级的,我们可以在页面中获取数据,hibernate的延时加载正常。

?

但是不知道为什么Struts2 + json + hibernate,那个延时加载失效了。

比如如果用session.load(),加载抛异常。只好用session.get了。

?

最后我网上找到解决方案了:

?

第一步:在web.xml配置页面级session(这一步早就完成)

<filter><filter-name>openSessionInView</filter-name><filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping><filter-name>openSessionInView</filter-name><url-pattern>/*</url-pattern></filter-mapping>

?

第二步:配置struts.xml中action的配置文件,

????????????? 只需要将.*hibernateLazyInitializer过滤就可以了。

<package name="money" extends="json-default" namespace="/"><action name="user" ><!--<param name="root">pm</param>--><param name="ignoreHierarchy" >false</param><!-- 设置JSON输出父类中的数据 --><param name="excludeProperties">.*hibernateLazyInitializer</param><!-- excludeProperties参数过滤不需要输出的数据字段 --></result></action></package>
?

就OK了。

读书人网 >JavaScript

热点推荐