struts2中的模型驱
来源:互联网 发布:西方文明简史知乎 编辑:程序博客网 时间:2024/04/28 04:10
action中的写法:
public class CategoryAction extends ActionSupport implements ModelDriven<Category>{private static final long serialVersionUID = 1L;private CategoryService cs = new CategoryService();public Category category = new Category(); //创建javabean实例public Category getCategory() {return category;}public void setCategory(Category category) {this.category = category;}@Overridepublic Category getModel() {return category;}public String List(){java.util.List<Category> list = cs.getList();ActionContext.getContext().put("list", list);return "list";}public String add(){cs.add(category);return List();}}
jsp中的写法:
</pre><pre name="code" class="java">
<span style="white-space:pre"></span><s:form action="/category_add" method="post" theme="simple"><s:textfield name="cname"></s:textfield><s:textfield name="cdate"></s:textfield><s:submit value="提交"></s:submit></s:form>
直接使用javabean的属性作为name可以取值与赋值。因为struts2是基于拦截器的,而模型驱动使用的拦截器是ModelDrivenInterceptor。其中的逻辑为:
@Override public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); if (action instanceof ModelDriven) { ModelDriven modelDriven = (ModelDriven) action; ValueStack stack = invocation.getStack(); Object model = modelDriven.getModel(); if (model != null) { stack.push(model);//将对象置入值栈中 } if (refreshModelBeforeResult) { invocation.addPreResultListener(new RefreshModelBeforeResult(modelDriven, model)); } } return invocation.invoke(); }
0 0
- struts2中的模型驱
- struts2中的域模型DTO接收参数
- Struts2中的属性驱动和模型驱动
- struts2模型
- Struts2的模型驱动
- struts2模型驱动
- struts2模型驱动
- struts2模型驱动
- struts2模型驱动
- Struts2的模型驱动
- Struts2的模型驱动
- JavaWeb -- Struts2 模型驱动
- Struts2模型驱动
- Struts2模型驱动
- Struts2的模型驱动
- Struts2的模型驱动
- struts2-ModelDriven模型驱动
- struts2模型驱动
- Thinkphp 关联关系一对多,取出数组
- Permutation(递归)
- HDOJ 2005 第几天?
- 乐学成语中出现的问题
- jQuery中的动画
- struts2中的模型驱
- (OK) netcat transfer file to android from fedora23
- 全志平台TP驱动
- Mendeley搭配WORD寫論文
- 系统结构-总
- MySQL配置文件my.cnf 详解
- Android中的多线程
- How to install Windows device driver, Vista, Vista x64, WinXP, WinXP x64 Window
- 区间dp(poj1651)