美文网首页
Struts2 Action中基本的数据对应方式

Struts2 Action中基本的数据对应方式

作者: 蘋果_283e | 来源:发表于2017-04-10 16:51 被阅读0次

    属性驱动(FieldDriven)

    1属性不多的情况用,只要表单中的元素名和action中的属性名一致同时有set get方法即可自动取值

    2(1)基本数据类型的属性对应,约定俗称:属性驱动

    用户:<input type="text" name="user">

    密码:<input type="password" name="pwd">

    <input type="submit" value="登录">

    public class Login extends ActionSupport {

    private String user,pwd;//有set get方法即可取值

    (2)JavaBean风格的属性对应,约定俗称:直接使用域对象。

    用户:<input type="text" name="user.user">

    密码:<input type="password" name="user.pwd">

    <input type="submit" value="登录">

    public class UserAction extends ActionSupport {

    private User user=new User();//取值用到javabean一定要有set get方法

    模型驱动(ModelDriven)

    public class UserAction extends ActionSupport implements ModelDriven<User>{

    private User user = new User();// 不需要有set get方法,但要有空参数的构造方法

    但一般还是要有set get

    @Override

    public String execute() throws Exception {

    if (user.getUser().equals("qq") && user.getPwd().equals("123")) {

    return SUCCESS;

    } else {

    return ERROR;

    }

    }

    public User getModel() {

    return user;

    }

    }

    相关文章

      网友评论

          本文标题:Struts2 Action中基本的数据对应方式

          本文链接:https://www.haomeiwen.com/subject/gkzsattx.html