标签:创建 override 泛型 ide color save 模型驱动 mod 接口
//1.创建一个UserBean public class User { private String username; private String pwd; public String getUsername() { return username; } public void setUsername(String username) { this.username = user name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } @Override public String toString() { return "User [username=" + username + ", pwd=" + pwd + "]"; } } public class UserAction1 { /* * 属性驱动-1 * 创建对应的属性,名称和jsp页面传递过来的参数名称一致 * 创建对应属性的get和set方法 */ private String username; private String pwd; public String add(){ System.out.println("账号:" + username); System.out.println("密码:" + pwd); return "success"; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } } /** * 属性驱动-2 * 封装为一个对象,jsp页面参数需要将name属性值设置为 【成员变 * 量.属性名称】的方式传递参数 * @author think * */ public class UserAction2 { private User user; public String save(){ System.out.println(user); return "success"; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } } /** * 模型驱动 * 1.实现ModelDriven接口,泛型传入的是接收的数据 * 2.创建成员变量,必须实例化model对象 * 3.实现getModel方法,返回model对象 * * @author think * */ public class UserAction3 implements ModelDriven<User>{ private User model = new User(); public String update(){ System.out.println(model); return "success"; } @Override public User getModel() { return model; } }
标签:创建 override 泛型 ide color save 模型驱动 mod 接口
原文地址:http://www.cnblogs.com/windmine/p/7306279.html