stuts2传参数的方式

1.通过属性传参数

public class UserAction extends ActionSupport {
 private String name;
 private int age;

 public String add() {
  <span style="white-space:pre">	</span>return SUCCESS;
   }

    public int getAge() {
        return age;
    }

    public String getName() {
        return name;
    }

   public void setAge(int age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }
}
调用方法:actionName.action?name=123&age=22


2.通过域模型传参数

public class UserAction extends ActionSupport {
 private User user;

 public String add() {
  <span>	</span>return SUCCESS;
   }

    public int get<span style="font-family: Arial, Helvetica, sans-serif;">User</span><span style="font-family: Arial, Helvetica, sans-serif;">() {</span>
        return <span style="font-family: Arial, Helvetica, sans-serif;">user</span><span style="font-family: Arial, Helvetica, sans-serif;">;</span>
    }

   public void setUser(User user) {
        this.user = user;
    }

}

public class User()
{
<div style="orphans: auto; text-align: start; widows: auto;">       <span>private<span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"> String name;</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>private int age;</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);">
</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>public void setName(String name)</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>{</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">		</span>this.name=name;</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>}</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>public void setAge(int age)</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>{</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">		</span>this.age=age;</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>}<span style="white-space:pre">	</span></span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>public String getName()</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>{<span style="white-space:pre">	</span></span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="white-space:pre">		</span>r</span>eturn this.name;</div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>}</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>public int getAge()</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>{<span style="white-space:pre">	</span></span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="white-space:pre">		</span>r</span>eturn this.age;</div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre">	</span>}</span></span></div>
}
调用方法:actionName.action?user.name=123&user.age=22


3.通过模型驱动传参数(Model Driven)

public class UserAction extends ActionSupport implements ModelDriven<User> {
    private User user = new User();

    public String add() {
        System.out.println("name:"+user.getName());
        System.out.println("age:"+user.getAge());
        return SUCCESS;
    }
    @Override
    public User getModel()
    {
        return user;
    }

}
调用方法:actionName.action?name=123&age=22


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值