• Struts2_用ModelDriven接收参数


    通过实现 ModelDriven 接口来接收请求参数,这种方法用的比较少,一般还是用前两种。

    请求:

     1 <a href="user/user!add?name=xiaoer&age=33">添加用户</a> 

    User类:

     1 package com.bjsxt.struts2.user.model;
     2 
     3 public class User {
     4     
     5     private String name;
     6     
     7     private int age;
     8 
     9     public String getName() {
    10         return name;
    11     }
    12 
    13     public void setName(String name) {
    14         this.name = name;
    15     }
    16 
    17     public int getAge() {
    18         return age;
    19     }
    20 
    21     public void setAge(int age) {
    22         this.age = age;
    23     }
    24     
    25 }
    View Code

    UserAction:

     1 package com.bjsxt.struts2.user.action;
     2 
     3 import com.bjsxt.struts2.user.model.User;
     4 import com.opensymphony.xwork2.ActionSupport;
     5 import com.opensymphony.xwork2.ModelDriven;
     6 
     7 public class UserAction extends ActionSupport implements ModelDriven<User>{
     8 
     9     private static final long serialVersionUID = -2514433281517403937L;
    10     
    11     User user = new User();
    12     
    13     public String add(){
    14         System.out.println("name = " + this.user.getName());
    15         System.out.println("age111 = " + this.user.getAge());
    16         return SUCCESS;
    17     }
    18 
    19     @Override
    20     public User getModel() {
    21         return this.user;
    22     }
    23 
    24 }

    结果:

    Struts2 主要关注的是 C 也就是 Controller 这一层。

    Struts2 对于实现了 ModelDriven 接口的Action的处理思路大致如图:

    链接: http://pan.baidu.com/s/1dFgQDvN 密码: hd3i

  • 相关阅读:
    redis导入导出工具redisdump,centos7安装使用
    mysql 锁表情况,处理笔记
    python语言
    pythonhello world
    常用单词
    Django课堂笔记 1
    JS之随机点名系统
    js之简易计算器
    JS之放大镜效果
    SQLServer索引漫谈
  • 原文地址:https://www.cnblogs.com/ShawnYang/p/6672695.html
Copyright © 2020-2023  润新知