struts2 的action 中模型赋值问题和懒加载问题

解决action中为模型赋值问题
不能直接为model赋值,没有改变栈顶的引用.
--------------------------------------
1.使用属性赋值(apache).
2.把新model压入栈顶.
ActionContext.getContext().getValueStack().push(s);
3.通过prepare拦截器 + paramsPrepareParamsStack组合,解决action的模型赋值问题
1.class SurveyAction ...{
public String designSurvey(){
...
}


public void prepareDesignSurvey(){
this.model = xxx ;
}
}


2.struts.xml配置文件中使用paramsPrepareParamsStack.




4.打开modelDriven的刷新模型属性.
struts.xml




true




懒加载问题
-----------------------------------
1.OpenSessionInView 过滤器
1.优点点:一劳永逸.

2.缺点:性能差.

在web.xml 配置


OpenSessionInViewFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter


OpenSessionInViewFilter
*.action


2.在service层强行初始化代理对象

在server 中强行加载:

例如:

/**
* 按照id查询调查,携带所有孩子
*/
public Survey getSurveyWithChildren(Integer sid){
Survey s = this.getSurvey(sid);
//初始化问题集合和页面集合
for(Page p : s.getPages()){
p.getQuestions().size();
}
return s; 
}

##视频位置  数据采集 1223

你可能感兴趣的:(struts2 的action 中模型赋值问题和懒加载问题)